Skip to content

"TextChoices" has no attribute "choices" #1858

@Kangaroux

Description

@Kangaroux

Bug report

What's wrong

When using an enum created from the functional enum API, mypy complains that the enum doesn't have an attribute choices, however it does.

How is that should be

choices should be a supported attribute when the enum is instantiated.

System information

  • OS:
  • python version: 3.10.12
  • django version: 4.2.8
  • mypy version: 1.7.1
  • django-stubs version: 4.2.7
  • django-stubs-ext version: 4.2.7

Repro

from django.db.models import TextChoices

print(TextChoices("test", "A B C").choices)
repro.py:3:1: error: "TextChoices" has no attribute "choices"  [attr-defined]

If you run the script you see the choices are printed correctly:

$ python repro.py 
[('A', 'A'), ('B', 'B'), ('C', 'C')]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomersstubsIssues in stubs files (.pyi)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions