Static type checking, part 1: SQLAlchemy 2.0 annotations #222
No reviewers
Labels
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: MarseyWorld/MarseyWorld#222
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "<deleted>:type-checking"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
SQLAlchemy 2.0 introduced a new way to create a Declarative table. Instead of passing the database type to
Column
, you provide the Python type as a PEP 484 type annotation wrapped inMapped
, and usemapped_column
instead ofColumn
. The database type will be inferred from the annotation:This new style allows the above constructs to be fully type-checked by static type checkers like Mypy and Pyright, making the code much easier to understand:
In the old style, all of these would have the type
Any
.typing is cringe
Pull request closed