Skip to content

Commit e57f91a

Browse files
authored
bpo-33866: enum: Stop using OrderedDict (GH-7698)
1 parent ea3dc80 commit e57f91a

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

Doc/library/enum.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ Iterating over the members of an enum does not provide the aliases::
281281
>>> list(Shape)
282282
[<Shape.SQUARE: 2>, <Shape.DIAMOND: 1>, <Shape.CIRCLE: 3>]
283283

284-
The special attribute ``__members__`` is an ordered dictionary mapping names
284+
The special attribute ``__members__`` is a read-only ordered mapping of names
285285
to members. It includes all names defined in the enumeration, including the
286286
aliases::
287287

@@ -998,7 +998,7 @@ Finer Points
998998
Supported ``__dunder__`` names
999999
""""""""""""""""""""""""""""""
10001000

1001-
:attr:`__members__` is an :class:`OrderedDict` of ``member_name``:``member``
1001+
:attr:`__members__` is a read-only ordered mapping of ``member_name``:``member``
10021002
items. It is only available on the class.
10031003

10041004
:meth:`__new__`, if specified, must create and return the enum members; it is

Lib/enum.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import sys
22
from types import MappingProxyType, DynamicClassAttribute
33

4-
# try _collections first to reduce startup cost
5-
try:
6-
from _collections import OrderedDict
7-
except ImportError:
8-
from collections import OrderedDict
9-
104

115
__all__ = [
126
'EnumMeta',
@@ -168,7 +162,7 @@ def __new__(metacls, cls, bases, classdict):
168162
# create our new Enum type
169163
enum_class = super().__new__(metacls, cls, bases, classdict)
170164
enum_class._member_names_ = [] # names in definition order
171-
enum_class._member_map_ = OrderedDict() # name->value map
165+
enum_class._member_map_ = {} # name->value map
172166
enum_class._member_type_ = member_type
173167

174168
# save attributes from super classes so we know if we can take
@@ -630,14 +624,12 @@ def _convert(cls, name, module, filter, source=None):
630624
source = vars(source)
631625
else:
632626
source = module_globals
633-
# We use an OrderedDict of sorted source keys so that the
634-
# _value2member_map is populated in the same order every time
627+
# _value2member_map_ is populated in the same order every time
635628
# for a consistent reverse mapping of number to name when there
636-
# are multiple names for the same number rather than varying
637-
# between runs due to hash randomization of the module dictionary.
629+
# are multiple names for the same number.
638630
members = [
639-
(name, source[name])
640-
for name in source.keys()
631+
(name, value)
632+
for name, value in source.items()
641633
if filter(name)]
642634
try:
643635
# sort by value

0 commit comments

Comments
 (0)