dropbox / sqlalchemy-stubs

Mypy plugin and stubs for SQLAlchemy
Apache License 2.0
570 stars 101 forks source link

None type not recognised for relationship. #173

Closed Dreamsorcerer closed 2 years ago

Dreamsorcerer commented 4 years ago
class Foo(DeclarativeBase):
    a = Column(String(128), nullable=False, index=True)
    bar = relationship(Something, foreign_keys=[a], primaryjoin="Foo.doi==Something.doi")

b = Foo(a="a")
if b.bar is None:  # unreachable code
    ...
print(b.bar)  # None

Mypy says that Foo().bar cannot be None, but it clearly can be.