python 3.10 improvements

This commit is contained in:
grillazz 2022-05-15 13:58:16 +02:00
parent 57a2e2bb6b
commit c37d89fa67
4 changed files with 4 additions and 6 deletions

View File

@ -1,5 +1,3 @@
from typing import List
from fastapi import APIRouter, Depends, HTTPException, status from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
@ -15,7 +13,7 @@ logger = get_logger(__name__)
@router.post("/add_many", status_code=status.HTTP_201_CREATED) @router.post("/add_many", status_code=status.HTTP_201_CREATED)
async def create_multi_stuff(payload: List[StuffSchema], db_session: AsyncSession = Depends(get_db)): async def create_multi_stuff(payload: list[StuffSchema], db_session: AsyncSession = Depends(get_db)):
try: try:
stuff_instances = [Stuff(name=stuf.name, description=stuf.description) for stuf in payload] stuff_instances = [Stuff(name=stuf.name, description=stuf.description) for stuf in payload]
db_session.add_all(stuff_instances) db_session.add_all(stuff_instances)

View File

@ -38,7 +38,7 @@ class Settings(BaseSettings):
jwt_access_toke_expire_minutes: int = os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", 1) jwt_access_toke_expire_minutes: int = os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", 1)
@lru_cache() @lru_cache
def get_settings(): def get_settings():
logger.info("Loading config settings from the environment...") logger.info("Loading config settings from the environment...")
return Settings() return Settings()

View File

@ -1,3 +1,3 @@
from the_app.models.nonsense import Nonsense # noqa from the_app.models.nonsense import Nonsense # noqa
from the_app.models.stuff import Stuff # noqa
from the_app.models.shakespeare import Character # noqa from the_app.models.shakespeare import Character # noqa
from the_app.models.stuff import Stuff # noqa

View File

@ -7,7 +7,7 @@ from rich.logging import RichHandler
console = Console(color_system="256", width=200, style="blue") console = Console(color_system="256", width=200, style="blue")
@lru_cache() @lru_cache
def get_logger(module_name): def get_logger(module_name):
logger = logging.getLogger(module_name) logger = logging.getLogger(module_name)
handler = RichHandler(rich_tracebacks=True, console=console, tracebacks_show_locals=True) handler = RichHandler(rich_tracebacks=True, console=console, tracebacks_show_locals=True)