sqlalchemy2-stubs icon indicating copy to clipboard operation
sqlalchemy2-stubs copied to clipboard

Mapped float columns always include Decimal in union type

Open alxdb opened this issue 4 years ago • 0 comments

Describe the bug if Float(asdecimal=False) (asdecimal=False is also the default behaviour for Float) is used as the type of a mapped column, the corresponding python type will be specified as Union[float, Decimal] even though it should never be a Decimal type.

Expected behavior Type of mapped column should be correctly determined, similarly to how relationships defined with or without the use of uselist=True are determined correctly.

To Reproduce

class Foo(Base):
    x = Column(Float(asdecimal=False))

y: Optional[float]
foo = Foo()
y = foo.x

Error This is a mypy error

Incompatible types in assignment (expression has type "Union[float, Decimal, None]", variable has type "Optional[float]")

Versions.

  • OS: Linux/MacOS
  • Python: 3.9
  • SQLAlchemy: 1.4.22
  • mypy: 0.910
  • SQLAlchemy2-stubs: 0.0.2a4

alxdb avatar Aug 03 '21 14:08 alxdb