-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
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
Changes from 1 commit
78b9f67
7693241
561dac5
0435142
4e93222
1fbf624
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -856,6 +856,8 @@ def _create_(cls, class_name, names, *, module=None, qualname=None, type=None, s | |
| value = first_enum._generate_next_value_(name, start, count, last_values[:]) | ||
| last_values.append(value) | ||
| names.append((name, value)) | ||
| if names is None: | ||
| names = () | ||
|
|
||
| # Here, names is either an iterable of (name, value) or a mapping. | ||
| for item in names: | ||
|
|
@@ -1112,6 +1114,11 @@ def __new__(cls, value): | |
| for member in cls._member_map_.values(): | ||
| if member._value_ == value: | ||
| return member | ||
| # still not found -- verify that members exist, in-case somebody got here mistakenly | ||
| # (such as via super when trying to override __new__) | ||
| if not cls._member_map_: | ||
| raise TypeError("%r has no members defined" % cls) | ||
| # | ||
|
Comment on lines
+1117
to
+1121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it ok to move
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 If you have no other alternative, you'll need to subclass There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| # still not found -- try _missing_ hook | ||
| try: | ||
| exc = None | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.