New submission from Luis E. <[email protected]>:
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@python
components: Documentation, Library (Lib)
messages: 364665
nosy: docs@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 <[email protected]>
<https://bugs.python.org/issue40025>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com