refactor: enhance type hinting and casting for improved type safety across multiple files

This commit is contained in:
Artem Kashaev
2025-12-01 16:44:14 +05:00
parent f234e60e65
commit 688ade0452
14 changed files with 62 additions and 42 deletions
+5 -5
View File
@@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Mapping
from datetime import datetime, timedelta, timezone
from typing import Any
from typing import Any, cast
import jwt
from app.core.config import settings
@@ -18,10 +18,10 @@ class PasswordHasher:
self._context = CryptContext(schemes=["pbkdf2_sha256"], deprecated="auto")
def hash(self, password: str) -> str:
return self._context.hash(password)
return cast(str, self._context.hash(password))
def verify(self, password: str, hashed_password: str) -> bool:
return self._context.verify(password, hashed_password)
return bool(self._context.verify(password, hashed_password))
class JWTService:
@@ -45,10 +45,10 @@ class JWTService:
}
if claims:
payload.update(claims)
return jwt.encode(payload, self._secret_key, algorithm=self._algorithm)
return cast(str, jwt.encode(payload, self._secret_key, algorithm=self._algorithm))
def decode(self, token: str) -> dict[str, Any]:
return jwt.decode(token, self._secret_key, algorithms=[self._algorithm])
return cast(dict[str, Any], jwt.decode(token, self._secret_key, algorithms=[self._algorithm]))
password_hasher = PasswordHasher()