Skip to content

Mapped float columns always include Decimal in union type  #145

Open
@alxdb

Description

@alxdb

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmypy pluginsomething that has to do with the sqlalchemy mypy plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions