Skip to content

Supporting __get__ and __set__ on Column object #170

Open
@rslinckx

Description

@rslinckx

The old sqlalchemy-stubs from dropbox included an approximation for the behavior of mapped classes using declarative setup, that is

class Foo(Model):
  a = Column(DateTime)

Foo.a
# type is Column[DateTime]
Foo().a
# type is datetime

They did so by defining the get method on Column here: https://github.com/dropbox/sqlalchemy-stubs/blob/master/sqlalchemy-stubs/sql/schema.pyi#L131

Maybe the same can be done for set, so that

Foo().a = 3
# wrong type, expected datetime object

Of course the whole thing is supported already when using the mypy plugin, but for example when using pylance (vscode type engine) which does not support plugins, it gets confused when using and assigning object values as mapped columns and complains about mismatching types.

I think the same is done on relationship() property

I'm unsure of the deeper implications of adding such type hints, though

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions