diff options
author | Gregory P. Smith ext:(%20%5BGoogle%20Inc.%5D) <greg@krypto.org> | 2016-06-03 19:14:52 (GMT) |
---|---|---|
committer | Gregory P. Smith ext:(%20%5BGoogle%20Inc.%5D) <greg@krypto.org> | 2016-06-03 19:14:52 (GMT) |
commit | 6f20bd6063380d47d4381295e3203466e762902c (patch) | |
tree | 9df36ad56d6acbd31026c2d78b07fdca41fa501c /Lib/enum.py | |
parent | 16931c3559689cfa9d98e3b56e612b7e1e635b7a (diff) | |
download | cpython-6f20bd6063380d47d4381295e3203466e762902c.zip cpython-6f20bd6063380d47d4381295e3203466e762902c.tar.gz cpython-6f20bd6063380d47d4381295e3203466e762902c.tar.bz2 |
signal, socket, and ssl module IntEnum constant name lookups now return a
consistent name for values having multiple names. Ex: signal.Signals(6)
now refers to itself as signal.SIGALRM rather than flipping between that
and signal.SIGIOT based on the interpreter's hash randomization seed.
This helps finish issue27167.
Diffstat (limited to 'Lib/enum.py')
-rw-r--r-- | Lib/enum.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index c3a0a8b..99db9e6 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -550,8 +550,14 @@ class Enum(metaclass=EnumMeta): source = vars(source) else: source = module_globals - members = {name: value for name, value in source.items() - if filter(name)} + # We use an OrderedDict of sorted source keys so that the + # _value2member_map is populated in the same order every time + # for a consistent reverse mapping of number to name when there + # are multiple names for the same number rather than varying + # between runs due to hash randomization of the module dictionary. + members = OrderedDict((name, source[name]) + for name in sorted(source.keys()) + if filter(name)) cls = cls(name, members, module=module) cls.__reduce_ex__ = _reduce_ex_by_name module_globals.update(cls.__members__) |