Author edd07
Recipients docs@python, edd07
Date 2020-03-20.11:25:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1584703504.0.0.0724934497115.issue40025@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-03-20 11:25:04edd07setrecipients: + edd07, docs@python
2020-03-20 11:25:04edd07setmessageid: <1584703504.0.0.0724934497115.issue40025@roundup.psfhosted.org>
2020-03-20 11:25:03edd07linkissue40025 messages
2020-03-20 11:25:03edd07create