[New-bugs-announce] [issue18508] enum.Enum population of _value2member_map does not match fallback search

Chris Lambacher report at bugs.python.org
Fri Jul 19 23:51:39 CEST 2013


New submission from Chris Lambacher:

When an Enum is being created, the _value2member_map class property is defined to speed lookup of Enum values later on. If the value does not exist then it falls back to a linear search through the _member_map.values() looking for member.value == value. This differs from population of the _value2member_map dictionary since population happens like this:
enum_class._value2member_map[value] = enum_member 

This differs because "value" is the value of the property in the definition, not the _value property of enum_member. In most cases this does not matter, but for instances where a __new__ or __init__ is doing something funky with the values (like auto-numbering) then the _value2member_map dict won't have the right information.

----------
messages: 193379
nosy: lambacck
priority: normal
severity: normal
status: open
title: enum.Enum population of _value2member_map does not match fallback search
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18508>
_______________________________________


More information about the New-bugs-announce mailing list