Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-using sqlalchemy.dialects.postgresql.UUID instance generates mypy violation #225

Open
mtvx opened this issue Aug 25, 2022 · 1 comment
Labels
bug Something isn't working mypy plugin something that has to do with the sqlalchemy mypy plugin

Comments

@mtvx
Copy link

mtvx commented Aug 25, 2022

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
@mtvx mtvx added the requires triage New issue that requires categorization label Aug 25, 2022
@CaselIT CaselIT added bug Something isn't working mypy plugin something that has to do with the sqlalchemy mypy plugin and removed requires triage New issue that requires categorization labels Aug 25, 2022
@mtvx
Copy link
Author

mtvx commented Aug 25, 2022

Also construction gives violation:

Foobar(
    works=uuid.uuid4(),
    doesnt=uuid.uuid4(),
)
$ mypy foobar.py
...
foobar.py:20: error: Unexpected keyword argument "doesnt" for "Foobar"  [call-arg]
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mypy plugin something that has to do with the sqlalchemy mypy plugin
Projects
None yet
Development

No branches or pull requests

2 participants