Typing support for PyDAL.
This package aims to improve the typing support for PyDAL. By using classes instead of the define_table method,
type hinting the result of queries can improve the experience while developing. In the background, the queries are still
generated and executed by pydal itself, this package only proves some logic to properly pass calls from class methods to
the underlying db.define_table pydal Tables.
TypeDAL is the replacement class for DAL that manages the code on top of DAL.
TypedTable must be the parent class of any custom Tables you define (e.g. class SomeTable(TypedTable))
TypedField can be used instead of Python native types when extra settings (such as default) are required (
e.g. name = TypedField(str, default="John Doe"))
TypedRows: can be used as the return type of .select() and subscribed with the actual table class, so
e.g. rows: TypedRows[SomeTable]. If you're lazy, list[SomeTable] works fine too but that misses hinting
possibilities such as .first().
name = TypedField(str, type="text", required=False)
name = StringField(required=False)
Caveats
This package depends heavily on the current implementation of annotations (which are computed when the class is
defined). PEP 563 (Postponed Evaluation of Annotations, accepted) aims to change this behavior (
and from __future__ import annotations already does) in a way that this module currently can not handle: all
annotations are converted to string representations. This makes it very hard to re-evaluate the annotation into the
original type, since the variable scope is lost (and thus references to variables or other classes are ambiguous or
simply impossible to find).
TypedField limitations; Since pydal implements some magic methods to perform queries, some features of typing will
not work on a typed field: typing.Optional or a union (Field() | None) will result in errors. The only way to make
a typedfield optional right now, would be to set required=False as an argument yourself. This is also a reason
why typing.get_type_hints is not a solution for the first caveat.