This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: enum.Enum population of _value2member_map does not match fallback search
Type: behavior Stage: resolved
Components: Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: ethan.furman, lambacck, python-dev
Priority: normal Keywords: patch

Created on 2013-07-19 21:51 by lambacck, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue18510.stoneleaf.01.patch ethan.furman, 2013-07-20 01:47 review
issue18510.stoneleaf.02.patch ethan.furman, 2013-07-20 02:09 review
Messages (3)
msg193379 - (view) Author: Chris Lambacher (lambacck) * Date: 2013-07-19 21:51
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.
msg193393 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2013-07-20 02:09
Cleaner patch.
msg193396 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-20 02:36
New changeset 37c427e3eb94 by Ethan Furman in branch 'default':
Close #18508 -- fix _value2member_map to always have the member's value
http://hg.python.org/cpython/rev/37c427e3eb94
History
Date User Action Args
2022-04-11 14:57:48adminsetgithub: 62708
2013-07-20 02:36:10python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg193396

resolution: fixed
stage: patch review -> resolved
2013-07-20 02:09:16ethan.furmansetfiles: + issue18510.stoneleaf.02.patch

messages: + msg193393
2013-07-20 01:47:12ethan.furmansetfiles: + issue18510.stoneleaf.01.patch
keywords: + patch
stage: patch review
2013-07-19 22:46:27ethan.furmansetassignee: ethan.furman

nosy: + ethan.furman
2013-07-19 21:51:39lambacckcreate