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

TextChoices api with human-readable name is not supported #2033

Closed
voidus opened this issue Mar 28, 2024 · 1 comment · Fixed by #2156
Closed

TextChoices api with human-readable name is not supported #2033

voidus opened this issue Mar 28, 2024 · 1 comment · Fixed by #2156

Comments

@voidus
Copy link
Contributor

voidus commented Mar 28, 2024

According to the django docs, this should be allowed:

    class YearInSchool(models.TextChoices):
        FRESHMAN = "FR", _("Freshman")
        SOPHOMORE = "SO", _("Sophomore")
        JUNIOR = "JR", _("Junior")
        SENIOR = "SR", _("Senior")
        GRADUATE = "GR", _("Graduate")

but since the constructor for Textchoices is defined like this:

    def __new__(cls, value: str) -> Self: ...

This is rejected by pyright in some situations. (I can talk about my setup some more, but in my personal situation it's not easy to work around)

Or maybe the constructor is not involved in this at all? Pyright gives me this not-really-helpful error:

/path/to/models.py
  /path/to/models.py:40:19 - error: Expected 1 positional argument (reportCallIssue)
  /path/to/models.py:41:50 - error: Expected 1 positional argument (reportCallIssue)
2 errors, 0 warnings, 0 informations 
``
@hubert-springbok
Copy link

Hi, we're also experiencing this since 4.2.6. Here is a minimal example to reproduce the error:

from django.db.models import TextChoices


class MyChoices(TextChoices):
    CHOICE = "CHOICE", "A choice"

django: 4.2.11
python: 3.10

Result: /test_file.py:5:14 - error: Expected 1 positional argument (reportCallIssue)

I've initially wrongly reported this to pyright.

mvaled added a commit to mvaled/django-stubs that referenced this issue May 13, 2024
sobolevn pushed a commit that referenced this issue May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants