5 ms·
The Annotated type is worth mentioning as well. Today in something like SQLModel you do (from the readme): class Hero(SQLModel, table=True): id: Op
by FreakLegion 4y ago
The Annotated type is worth mentioning as well. Today in something like SQLModel you do (from the readme):
class Hero(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
And that's fine. I wouldn't necessarily change anything here. Annotated gives you the option of approaching things in a different way, though.
class Hero(SQLModel, table=True):
id: PrimaryKey[Optional[int]] = None
I have some use cases where the alternative approach is useful, like quantification of class fields or function arguments.
- eirki 4y agoFastApi very recently added support for Annotated, and now recommends using that over default arguments. https://fastapi.tiangolo.com/release-notes/#0950 https://fastapi.tiangolo.com/release-notes/#0950