[New-bugs-announce] [issue40025] enum: _generate_next_value_ is not called if its definition occurs after calls to auto()
Luis E.
report at bugs.python.org
Fri Mar 20 07:25:04 EDT 2020
New submission from Luis E. <edd at asustin.net>:
I ran into this issue when attempting to add a custom _generate_next_value_ method to an existing Enum. Adding the method definition to the bottom of the class causes it to not be called at all:
from enum import Enum, auto
class E(Enum):
A = auto()
B = auto()
def _generate_next_value_(name, *args):
return name
E.B.value # Returns 2, E._generate_next_value_ is not called
class F(Enum):
def _generate_next_value_(name, *args):
return name
A = auto()
B = auto()
F.B.value # Returns 'B', as intended
I do not believe that the order of method/attribute definition should affect the behavior of the class, or at least it should be mentioned in the documentation.
----------
assignee: docs at python
components: Documentation, Library (Lib)
messages: 364665
nosy: docs at python, edd07
priority: normal
severity: normal
status: open
title: enum: _generate_next_value_ is not called if its definition occurs after calls to auto()
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40025>
_______________________________________
More information about the New-bugs-announce
mailing list