pylint-django
pylint-django copied to clipboard
Instance of 'tuple' has no 'label' member (no-member)
Accessing the .label member for a models.TextChoices enumeration type https://docs.djangoproject.com/en/3.0/ref/models/fields/#enumeration-types raises this pylint error: Instance of 'tuple' has no 'label' member (no-member). Is this something that would make sense to fix in pylint-django?
Repro:
class Student(models.Model):
class YearInSchool(models.TextChoices):
FRESHMAN = 'FR', _('Freshman')
SOPHOMORE = 'SO', _('Sophomore')
JUNIOR = 'JR', _('Junior')
SENIOR = 'SR', _('Senior')
GRADUATE = 'GR', _('Graduate')
YearInSchool.FRESHMAN.label
It could be done in pylint-django, the best thing to do I would say is to add a transform to convert properties of models.TextChoices classes to some faked class. Though I don't know what that class does, I'd never heard of it and always used django-model-utils for that kind of thing :-)
From the docs:
A .label property is added on values, to return the human-readable name.
A number of custom properties are added to the enumeration classes – .choices, .labels, .values, and .names – to make it easier to access lists of those separate parts of the enumeration. Use .choices as a suitable value to pass to choices in a field definition.
I guess that we'll have to apply the same transformation like Django does. FTR I also haven't used these fields before. Looks easy but will probably take a day of work. PRs are welcome.
I've created a test case. Coule you give me a pointer where I would add the attirbute to the TextChoices tuples?