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

Incompatible with djang-enums #211

Open
syserr0r opened this issue Nov 7, 2023 · 1 comment
Open

Incompatible with djang-enums #211

syserr0r opened this issue Nov 7, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@syserr0r
Copy link

syserr0r commented Nov 7, 2023

For a model Model with a field such as:

class TestModel(django.db.models.Model):
    bar = django_enum.EnumField(enums.Bar, default=enums.Bar.FOO)

and code such as:

foo = TestModel()
foo.bar = enums.Bar.FOO

gives the following in pyright:

Cannot assign member "bar" for type "TestModel"
  "Literal[Bar.FOO]" is incompatible with "_ST@Field"

The VSCode IDE which also uses pyright reports the same error however when inspecting the field type it is shown as _GT@Field

Forcing the type in the model definition as EnumMixin such as follows, makes no difference:

class TestModel(django.db.models.Model):
    bar: django_enum.fields.EnumMixin = django_enum.EnumField(enums.Bar, default=enums.Bar.FOO)

I'd rather not disable type checking on all django-enum assignments if I can avoid it.
Should I be raising this with the djang-enum project instead?

Any help/advice greatly appreciated

@sbdchd
Copy link
Owner

sbdchd commented Nov 10, 2023

Hmm this is tricky!
I believe I used django-enum on a past project, but can't remember how we got it to work or if we stopped using it

It might make sense to create type stubs for django-enum (.pyi files) to get pyright / mypy to behave

@sbdchd sbdchd added the bug Something isn't working label Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants