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

Enum imported from another module raises "Incompatible types error" #153

Open
abprime opened this issue Aug 19, 2021 · 0 comments
Open

Enum imported from another module raises "Incompatible types error" #153

abprime opened this issue Aug 19, 2021 · 0 comments
Labels
bug Something isn't working mypy plugin something that has to do with the sqlalchemy mypy plugin

Comments

@abprime
Copy link

abprime commented Aug 19, 2021

The following code runs fine without any mypy error

# file_type.py
from enum import Enum
from sqlalchemy.dialects.postgresql import ENUM

class FileType(str, Enum):
    CSV = "CSV"
    XLSX = "XLSX"

file_type_db_enum = ENUM(FileType, name="file_type")
# input_file.py
from file_type import FileType
from sqlalchemy import Column
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
class InputFile(Base):
    file_type: FileType = Column(ENUM(FileType, name="file_type"))

But changing input file to following throws mypy error

# input_file.py
from file_type import file_type_db_enum
from sqlalchemy import Column
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
class InputFile(Base):
    file_type: FileType = Column(file_type_db_enum)
input_file.py:7: error: Incompatible types in assignment (expression has type "Column[NullType]", variable has type "FileType")

Note : I am importing the file_type_db_enum, as it is being reused by multiple other models, and also, because graphene-sqlalchemy wants it to be declared this way, Otherwise it generates conflicts for multiple objectType with the same name.

Expected behavior
This should not raise any errors.

To Reproduce

# file_type.py
from enum import Enum
from sqlalchemy.dialects.postgresql import ENUM

class FileType(str, Enum):
    CSV = "CSV"
    XLSX = "XLSX"

file_type_db_enum = ENUM(FileType, name="file_type")

# input_file.py
from file_type import file_type_db_enum
from sqlalchemy import Column
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
class InputFile(Base):
    file_type: FileType = Column(file_type_db_enum)

Error

input_file.py:7: error: Incompatible types in assignment (expression has type "Column[NullType]", variable has type "FileType")

Versions.

  • OS: Windows 10
  • Python: 3.8.10
  • SQLAlchemy: 1.4.22
  • mypy: 0.910
  • SQLAlchemy2-stubs: 0.0.2a8
@abprime abprime added the requires triage New issue that requires categorization label Aug 19, 2021
@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 19, 2021
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