django-stubs: `TextChoices` subclasses declared inside a class cause "Unable to resolve type of choices property" error
Bug report
What’s wrong
Having an enum that extends TextChoices declared inside another class (e.g. a model), results in the following error when running mypy:
file.py: error: Unable to resolve type of choices property [misc]
Here’s an example of such definition:
class MyModel:
class MyEnum(models.TextChoices):
foo = "foo", "Foo"
bar = "bar", "Bar"
a = MyEnum.foo
Running mypy against that:
file.py:9: error: Unable to resolve type of choices property [misc]
How is that should be
No error should happen.
System information
- OS:
pythonversion: 3.12.9djangoversion: 5.1.8mypyversion: 1.13.0django-stubsversion: 5.2.0django-stubs-extversion: 5.2.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 18 (14 by maintainers)
Commits related to this issue
- Fix aliasing of choices in a class in choices plugin Another fix for a3f2a558fc6c5544b3b46a6e53e6f266272236f7 (#2582) Follow up to c37850b62a7217129e75f9985da37c2870b6b069 (#2646) Fixes #2665 — committed to ngnpope/django-stubs by ngnpope a year ago
- Fix aliasing of choices in a class in choices plugin Another fix for a3f2a558fc6c5544b3b46a6e53e6f266272236f7 (#2582) Follow up to c37850b62a7217129e75f9985da37c2870b6b069 (#2646) Fixes #2665 — committed to ngnpope/django-stubs by ngnpope a year ago
- Fix aliasing of choices in a class in choices plugin (#2734) Another fix for a3f2a558fc6c5544b3b46a6e53e6f266272236f7 (#2582) Follow up to c37850b62a7217129e75f9985da37c2870b6b069 (#2646) Fixes #266... — committed to joshuadavidthomas/django-stubs by ngnpope a year ago
Sorry, my previous example was illustrative; here’s an actual repro:
Thanks
@youtux Could you try installing from the
masterbranch? I think this should be fixed by #2646.