🏷️ Add mypy to the GitHub Action for tests and fixed types in the whole project (#655)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Esteban Maya
2024-03-10 14:47:21 -05:00
committed by GitHub
parent 6607eaded4
commit a230f4fb2c
19 changed files with 106 additions and 79 deletions

View File

@@ -68,7 +68,7 @@ class Settings(BaseSettings):
@field_validator("EMAILS_FROM_NAME")
def get_project_name(cls, v: str | None, info: ValidationInfo) -> str:
if not v:
return info.data["PROJECT_NAME"]
return str(info.data["PROJECT_NAME"])
return v
EMAIL_RESET_TOKEN_EXPIRE_HOURS: int = 48
@@ -89,7 +89,7 @@ class Settings(BaseSettings):
FIRST_SUPERUSER: str
FIRST_SUPERUSER_PASSWORD: str
USERS_OPEN_REGISTRATION: bool = False
model_config = SettingsConfigDict(case_sensitive=True)
model_config = SettingsConfigDict(env_file=".env")
settings = Settings()
settings = Settings() # type: ignore

View File

@@ -12,13 +12,8 @@ pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
ALGORITHM = "HS256"
def create_access_token(subject: str | Any, expires_delta: timedelta = None) -> str:
if expires_delta:
expire = datetime.utcnow() + expires_delta
else:
expire = datetime.utcnow() + timedelta(
minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES
)
def create_access_token(subject: str | Any, expires_delta: timedelta) -> str:
expire = datetime.utcnow() + expires_delta
to_encode = {"exp": expire, "sub": str(subject)}
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt