Skip to content

Instantly share code, notes, and snippets.

View diogommartins's full-sized avatar
🚀

Diogo Magalhães Machado diogommartins

🚀
View GitHub Profile
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))
import asyncio
import logging
import sys
async def log_it(logger, content):
logger.info(content)
async def main():
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))
)
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)
produtos = [
Produto(Decimal("700")),
Produto(Decimal("3000.0"))
]
print(total_carrinho(produtos))
print(total_carrinho(tuple(produtos)))
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)
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] = []
x: str = "Xena"
def soma(a: int, b: int) -> int:
return a + b
print(soma.__annotations__)
print(__annotations__)
x: int
def soma(a: int, b: int) -> int: ...
def a_func(a:int, b: int=...) -> int: ...
x = 666
def soma(a, b):
return a + b
def a_func(a, b=42):
return a + b