This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from asyncio.log import logger | |
import os | |
logging.basicConfig(level=logging.DEBUG) | |
fileno = logger.manager.root.handlers[0].stream.fileno() | |
print(os.get_blocking(fileno)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import logging | |
import sys | |
async def log_it(logger, content): | |
logger.info(content) | |
async def main(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import aiologger | |
async def main(): | |
logger = aiologger.Logger.with_default_handlers(level=10) | |
await asyncio.gather( | |
*(logger.info("Hello world !") for _ in range(10_000)) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NewType | |
Metros = NewType('Metros', float) | |
Pes = NewType('Pes', float) | |
Segundos = NewType('Segundos', float) | |
MetrosPorSegundo = NewType('MetrosPorSegundo', float) | |
def velocidade(distancia: Metros, tempo: Segundos) ->MetrosPorSegundo: | |
return MetrosPorSegundo(distancia / tempo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
produtos = [ | |
Produto(Decimal("700")), | |
Produto(Decimal("3000.0")) | |
] | |
print(total_carrinho(produtos)) | |
print(total_carrinho(tuple(produtos))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal | |
from typing import List, NamedTuple, Union | |
class Produto(NamedTuple): | |
preco: Union[Decimal, float] | |
def total_carrinho(produtos: List[Produto]) -> Union[Decimal, float]: | |
return sum(p.preco for p in produtos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from typing import List | |
from pydantic import BaseModel | |
class User(BaseModel): | |
id: int | |
name = 'John Doe' | |
signup_ts: datetime = None | |
friends: List[int] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x: str = "Xena" | |
def soma(a: int, b: int) -> int: | |
return a + b | |
print(soma.__annotations__) | |
print(__annotations__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x: int | |
def soma(a: int, b: int) -> int: ... | |
def a_func(a:int, b: int=...) -> int: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = 666 | |
def soma(a, b): | |
return a + b | |
def a_func(a, b=42): | |
return a + b |