bpo-40025:The behavior is the same when _generate_next_value_ is defined afte…#19904
bpo-40025:The behavior is the same when _generate_next_value_ is defined afte…#19904hongweipeng wants to merge 8 commits into
_generate_next_value_ is defined afte…#19904Conversation
…r or before members
ethanfurman
left a comment
There was a problem hiding this comment.
I like the idea, but it needs more work. Currently, even if _generate_next_value_ is defined before any members it still will not be called until after the entire Enum is defined and given to EnumMeta.__new__ for final processing, which means that somebody wanting to do interesting things with previous member values would not be able to.
In _EnumDict you'll need to track if auto() has been seen yet, if _generate_next_value_ was defined before any uses of auto() were, and call _generate_next_value_ within _EnumDict if and only if _generate_next_value_ was defined before all uses of auto().
So this should work:
class Test1(Enum):
def _generate_next_value(...):
return 12
first = auto()
second = first + 9
and this should fail:
class Test2(Enum):
first = auto()
def _generate_next_value(...):
return 12
second = first + 9
Also, make sure you have spaces after commas, etc.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be put in the comfy chair! |
This comment has been minimized.
This comment has been minimized.
|
Thanks for making the requested changes! @ethanfurman: please review the changes made to this pull request. |
|
I had hoped to incorporate this idea when I had time to look at it further; unfortunately, now that I have I do not see a way to support the following use-case (which I believe would be much more common): HongWeipeng, thank you for trying. |
…r or before members
https://bugs.python.org/issue40025