summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPieter Eendebak <pieter.eendebak@gmail.com>2023-10-16 20:37:54 (GMT)
committerGitHub <noreply@github.com>2023-10-16 20:37:54 (GMT)
commita77180e6633a3aca4011b175c2ac65aa33795035 (patch)
tree6b44e9672faa73b9356f57c1e39f59470c22a165
parentf07ca27709855d4637b43bba23384cc795143ee3 (diff)
downloadcpython-a77180e6633a3aca4011b175c2ac65aa33795035.zip
cpython-a77180e6633a3aca4011b175c2ac65aa33795035.tar.gz
cpython-a77180e6633a3aca4011b175c2ac65aa33795035.tar.bz2
gh-110905: [Enum] minor fixes and cleanup (GH-110906)
-rw-r--r--Lib/enum.py8
-rw-r--r--Lib/test/test_enum.py2
2 files changed, 4 insertions, 6 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index f5448a1..7d6e51d 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -61,8 +61,8 @@ def _is_sunder(name):
return (
len(name) > 2 and
name[0] == name[-1] == '_' and
- name[1:2] != '_' and
- name[-2:-1] != '_'
+ name[1] != '_' and
+ name[-2] != '_'
)
def _is_internal_class(cls_name, obj):
@@ -81,7 +81,6 @@ def _is_private(cls_name, name):
if (
len(name) > pat_len
and name.startswith(pattern)
- and name[pat_len:pat_len+1] != ['_']
and (name[-1] != '_' or name[-2] != '_')
):
return True
@@ -156,7 +155,6 @@ def _dedent(text):
Like textwrap.dedent. Rewritten because we cannot import textwrap.
"""
lines = text.split('\n')
- blanks = 0
for i, ch in enumerate(lines[0]):
if ch != ' ':
break
@@ -1639,7 +1637,7 @@ def _simple_enum(etype=Enum, *, boundary=None, use_args=None):
Class decorator that converts a normal class into an :class:`Enum`. No
safety checks are done, and some advanced behavior (such as
:func:`__init_subclass__`) is not available. Enum creation can be faster
- using :func:`simple_enum`.
+ using :func:`_simple_enum`.
>>> from enum import Enum, _simple_enum
>>> @_simple_enum(Enum)
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 8c1f285..8b99c3e 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -171,7 +171,7 @@ class TestHelpers(unittest.TestCase):
sunder_names = '_bad_', '_good_', '_what_ho_'
dunder_names = '__mal__', '__bien__', '__que_que__'
- private_names = '_MyEnum__private', '_MyEnum__still_private'
+ private_names = '_MyEnum__private', '_MyEnum__still_private', '_MyEnum___triple_private'
private_and_sunder_names = '_MyEnum__private_', '_MyEnum__also_private_'
random_names = 'okay', '_semi_private', '_weird__', '_MyEnum__'