Fix enum stubs: move __init__ to __new__ for IntegerChoices/TextChoices#3215
Open
ahmedasar00 wants to merge 2 commits intotypeddjango:masterfrom
Open
Fix enum stubs: move __init__ to __new__ for IntegerChoices/TextChoices#3215ahmedasar00 wants to merge 2 commits intotypeddjango:masterfrom
ahmedasar00 wants to merge 2 commits intotypeddjango:masterfrom
Conversation
91ae6a3 to
3761818
Compare
| # Django's ChoicesType metaclass processes (value, label) tuples at class definition time, | ||
| # but the runtime __new__ (from enum.Enum) only accepts (cls, value). | ||
| # We keep the label overload so that defining enum members type-checks correctly. | ||
| django.db.models.enums.IntegerChoices.__new__ |
Contributor
There was a problem hiding this comment.
I have absolutely no clue if any of that is correct. Do you have any ideas @ngnpope ?
Member
There was a problem hiding this comment.
Not sure I'll have time to look into it this week
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #3148
Summary
Partially addresses stubtest inconsistencies in
IntegerChoicesand
TextChoicescaused by Python 3.14 enum changes.Changes
__init__to__new__inenums.pyix→value,object→value)IntegerChoicesto reference__new__Results
labelparameter remains)Remaining issue
The runtime
__new__signature is just(cls, value)— nolabelparameter. The label is handled by the metaclassChoicesType.__new__during class creation.Keeping
labelin the stubs is useful for type checking butdoesn't match the runtime. Looking for guidance on whether to:
labelto match runtime exactly