Skip to content

TextChoices subclasses declared inside a class cause "Unable to resolve type of choices property" error #2665

Open
@youtux

Description

@youtux

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:
  • python version: 3.12.9
  • django version: 5.1.8
  • mypy version: 1.13.0
  • django-stubs version: 5.2.0
  • django-stubs-ext version: 5.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions