Skip to content

Commit

Permalink
refactor: Fix types for ModelProtocal and BasicAttributes (#243)
Browse files Browse the repository at this point in the history
Fix types for ModelProtocal and BasicAttributes

It's imposible to get_type_hints() otherwise without monkey patching or other shenanigans.

Signed-off-by: Rey092 <[email protected]>
  • Loading branch information
Rey092 authored Aug 4, 2024
1 parent 3f7fee3 commit dcf3670
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions advanced_alchemy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ def merge_table_arguments(cls: type[DeclarativeBase], table_args: TableArgsType
class ModelProtocol(Protocol):
"""The base SQLAlchemy model protocol."""

__table__: FromClause
__mapper__: Mapper[Any]
__name__: str
if TYPE_CHECKING:
__table__: FromClause
__mapper__: Mapper[Any]
__name__: str

def to_dict(self, exclude: set[str] | None = None) -> dict[str, Any]:
"""Convert model to dictionary.
Expand Down Expand Up @@ -203,9 +204,10 @@ class AuditColumns:
class BasicAttributes:
"""Basic attributes for SQLALchemy tables and queries."""

__name__: str
__table__: FromClause
__mapper__: Mapper[Any]
if TYPE_CHECKING:
__name__: str
__table__: FromClause
__mapper__: Mapper[Any]

def to_dict(self, exclude: set[str] | None = None) -> dict[str, Any]:
"""Convert model to dictionary.
Expand Down

0 comments on commit dcf3670

Please sign in to comment.