Skip to content

Commit 9d6908c

Browse files
committed
more fixes
1 parent 694d8f7 commit 9d6908c

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Doc/library/enum.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,8 @@ Data Types
834834
for defining enum classes (see :ref:`prepare`).
835835
It is exposed to allow subclasses of :class:`EnumType` with advanced
836836
behavior like having multiple values per member.
837-
It prevents reusing member names, with special behavior for names that
838-
start with an underscore.
837+
It should be called with the name of the enum class being created, otherwise
838+
private names and internal classes will not be handled correctly.
839839

840840
Note that only the :class:`~collections.abc.MutableMapping` interface
841841
(:meth:`~object.__setitem__` and :meth:`~dict.update`) is overridden.

Lib/enum.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class EnumDict(dict):
342342
EnumType will use the names found in self._member_names as the
343343
enumeration member names.
344344
"""
345-
def __init__(self, cls_name):
345+
def __init__(self, cls_name=None):
346346
super().__init__()
347347
self._member_names = {} # use a dict -- faster look-up than a list, and keeps insertion order since 3.7
348348
self._last_values = []
@@ -359,7 +359,7 @@ def __setitem__(self, key, value):
359359
360360
Single underscore (sunder) names are reserved.
361361
"""
362-
if _is_private(self._cls_name, key):
362+
if self._cls_name is not None and _is_private(self._cls_name, key):
363363
# do nothing, name will be a normal attribute
364364
pass
365365
elif _is_sunder(key):
@@ -407,7 +407,7 @@ def __setitem__(self, key, value):
407407
value = value.value
408408
elif _is_descriptor(value):
409409
pass
410-
elif _is_internal_class(self._cls_name, value):
410+
elif self._cls_name is not None and _is_internal_class(self._cls_name, value):
411411
# do nothing, name will be a normal attribute
412412
pass
413413
else:

Lib/test/test_enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5459,7 +5459,7 @@ class MyClass(metaclass=Meta):
54595459

54605460
def test_enum_dict_standalone(self):
54615461
"""Test that EnumDict is usable on its own"""
5462-
enumdict = EnumDict('test')
5462+
enumdict = EnumDict()
54635463
enumdict['a'] = 1
54645464

54655465
with self.assertRaises(TypeError):

0 commit comments

Comments
 (0)