Open
Description
Describe the bug
Storing an instance of sqlalchemy.dialects.postgresql.UUID
to a variable and re-using that in the column declarations is seen as NullType
.
Expected behavior
Type should be detected as Column[UUID]
?
To Reproduce
from typing import Optional
from uuid import UUID
from sqlalchemy import Column
from sqlalchemy.dialects.postgresql import UUID as PostgresUUID
from sqlalchemy.orm import declarative_base
PgUUID = PostgresUUID(as_uuid=True)
Base = declarative_base()
class Foobar(Base):
__tablename__ = "foobar"
works: Optional[UUID] = Column(PostgresUUID(as_uuid=True))
doesnt: Optional[UUID] = Column(PgUUID)
Error
Running with sqlalchemy.ext.mypy.plugin
enabled in mypy
configs:
$ mypy foobar.py
foobar.py:15: error: Incompatible types in assignment (expression has type "Column[NullType]", variable has type "UUID") [assignment]
Found 1 error in 1 file (checked 1 source file)
Versions.
- OS: Linux
- Python:
3.9.9
- SQLAlchemy:
1.4.39
- mypy:
mypy 0.971
- SQLAlchemy2-stubs:
0.0.2a25