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

The functional API for Django's enumeration types isn't supported #729

Closed
kevinmarsh opened this issue Oct 15, 2021 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@kevinmarsh
Copy link
Contributor

Bug report

What's wrong

The functional API for Django's Enumeration types doesn't seem to be supported.

These two run fine:

# Example from https://docs.python.org/3/library/enum.html#functional-api
from enum import Enum
Animal = Enum('Animal', 'ANT BEE CAT DOG')

# Example from: https://docs.djangoproject.com/en/3.2/ref/models/fields/#enumeration-types
from django.db import models
class Vehicle(models.TextChoices):
     CAR = 'C'
     TRUCK = 'T'
     JET_SKI = 'J'

But this raises an error:

# Example from: https://docs.djangoproject.com/en/3.2/ref/models/fields/#enumeration-types
from django.db import models
MedalType = models.TextChoices('MedalType', 'GOLD SILVER BRONZE')
my_file.py:3: error: No overload variant of "TextChoices" matches argument types "str", "str"
my_file.py:3: note: Possible overload variant:
my_file.py:3: note:     def __new__(cls, o: bytes, encoding: str = ..., errors: str = ...) -> TextChoices
my_file.py:3: note:     <1 more non-matching overload not shown>

How is that should be

The resulting enum's type should be the same whether you use the normal class based approach or the functional API approach.

System information

  • OS: linux
  • python version: 3.9.7
  • django version: 3.2.8
  • mypy version: 0.910
  • django-stubs version: 1.9.0
  • django-stubs-ext version: 0.3.1
@kevinmarsh kevinmarsh added the bug Something isn't working label Oct 15, 2021
@adamchainz
Copy link
Contributor

I believe this is due to a Mypy bug: python/mypy#6037 . It sounds like Mypy’s enum support needs extending.

I think we can’t do anything here, so closing, but thank you for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants