refactor: enhance type hinting and casting for improved type safety across multiple files
This commit is contained in:
@@ -10,9 +10,11 @@ from pydantic import BaseModel, ConfigDict, Field
|
||||
from sqlalchemy import DateTime, ForeignKey, Integer, func, text
|
||||
from sqlalchemy import Enum as SqlEnum
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.engine import Dialect
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.types import JSON as SA_JSON
|
||||
from sqlalchemy.types import TypeDecorator
|
||||
from sqlalchemy.sql.type_api import TypeEngine
|
||||
|
||||
from app.models.base import Base, enum_values
|
||||
|
||||
@@ -31,7 +33,7 @@ class JSONBCompat(TypeDecorator):
|
||||
impl = JSONB
|
||||
cache_ok = True
|
||||
|
||||
def load_dialect_impl(self, dialect): # type: ignore[override]
|
||||
def load_dialect_impl(self, dialect: Dialect) -> TypeEngine[Any]:
|
||||
if dialect.name == "sqlite":
|
||||
from sqlalchemy.dialects.sqlite import JSON as SQLITE_JSON # local import
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ class Base(DeclarativeBase):
|
||||
"""Base class that configures naming conventions."""
|
||||
|
||||
@declared_attr.directive
|
||||
def __tablename__(cls) -> str: # type: ignore[misc] # noqa: N805 - SQLAlchemy expects cls
|
||||
def __tablename__(cls) -> str: # noqa: N805 - SQLAlchemy expects cls
|
||||
return cls.__name__.lower()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user