-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ #108704
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
78b9f67
[Enum] raise TypeError if super().__new__ called in custom __new__
ethanfurman 7693241
Update Doc/howto/enum.rst
ethanfurman 561dac5
fix whitespace
ethanfurman 0435142
proliferate __new__ warning
ethanfurman 4e93222
remove warning, add link to detail section
ethanfurman 1fbf624
fix reference
ethanfurman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to move
_member_map_
check after_missing_
hook?I have a derived class has no members and hook
_missing_
, it raise exception here.@ethanfurman
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, no. I tried to do that, but then the bug wasn't fixed.
What does your
missing()
hook do?If you have no other alternative, you'll need to subclass
EnumType
and override the__call__
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick reply. here is an example:
which prints
before this change.
As my understanding, hook
_missing_
handle the missing input, a dynamic value in the above case.so I raise the question: hook
_missing_
before empty check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll chime in here as well. I have the same question and got hit by this change as well. We have a setup where we do like:
Previously, Result(0) returned CommonResult.OK. Now throws. It was a nifty pattern to use, and it sort of breaks the combination of using the
_missing_
and subclasses of Enum.