sqlalchemy-stubs
sqlalchemy-stubs copied to clipboard
Add support for foreign keys
We could add a plugin that would allow to infer types for keys referenced by their names in other tables/models. This would likely require some extensive changes to mypy (because of implicit dependencies between modules/targets), so this is low priority.
A more important use case here, is to automatically infer RelationshipProperty[Cls] for relationship('Cls', ...) (note the string literal). There is a simple way to implement this, but it requires Cls to be available (imported) in the current scope (at least under if typing.TYPE_CHECKING: ...).
Actually the relationship use case looks important (and there is a simple although limited way to implement this), so raising priority to normal.
Note that the relationship part was partially implemented in #49.