To add to this, if you are using mypy you can use this package: https://github.com/dropbox/sqlalchemy-stubs

If you are using pyright or any other static type checker, you probably want to do something similar to what this package (https://github.com/sbdchd/django-types) does to django. An example for `IntegerField`: https://github.com/sbdchd/django-types/blob/main/django-stubs/db/models/fields/__init__.pyi#L128

Note that different from django, which define a different field to each type (i.e. CharField for str, IntegerField for int, etc), sqlalchemy uses a parameter for that. So you probably want to define a single `Column` and an `overload` for its `__init__`/`__new__` methods for each possible column typetype to return a different descriptor to match the configuration, probably also taking `nullable` into consideration to type it as `<type> | None`.

On Sun, Mar 5, 2023 at 12:46 PM Eric Traut <eric@traut.com> wrote:
You can annotate the class variable as a class that implements the descriptor protocol (`__get__` and `__set__` methods). That way, it can return a different type when accessed through an instance of `Entity`.
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: hackedbellini@gmail.com


--
Thiago Bellini Ribeiro | https://bellini.dev