mirror of https://github.com/python/cpython
gh-110905: [Enum] minor fixes and cleanup (GH-110906)
This commit is contained in:
parent
f07ca27709
commit
a77180e663
|
@ -61,8 +61,8 @@ def _is_sunder(name):
|
||||||
return (
|
return (
|
||||||
len(name) > 2 and
|
len(name) > 2 and
|
||||||
name[0] == name[-1] == '_' and
|
name[0] == name[-1] == '_' and
|
||||||
name[1:2] != '_' and
|
name[1] != '_' and
|
||||||
name[-2:-1] != '_'
|
name[-2] != '_'
|
||||||
)
|
)
|
||||||
|
|
||||||
def _is_internal_class(cls_name, obj):
|
def _is_internal_class(cls_name, obj):
|
||||||
|
@ -81,7 +81,6 @@ def _is_private(cls_name, name):
|
||||||
if (
|
if (
|
||||||
len(name) > pat_len
|
len(name) > pat_len
|
||||||
and name.startswith(pattern)
|
and name.startswith(pattern)
|
||||||
and name[pat_len:pat_len+1] != ['_']
|
|
||||||
and (name[-1] != '_' or name[-2] != '_')
|
and (name[-1] != '_' or name[-2] != '_')
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
|
@ -156,7 +155,6 @@ def _dedent(text):
|
||||||
Like textwrap.dedent. Rewritten because we cannot import textwrap.
|
Like textwrap.dedent. Rewritten because we cannot import textwrap.
|
||||||
"""
|
"""
|
||||||
lines = text.split('\n')
|
lines = text.split('\n')
|
||||||
blanks = 0
|
|
||||||
for i, ch in enumerate(lines[0]):
|
for i, ch in enumerate(lines[0]):
|
||||||
if ch != ' ':
|
if ch != ' ':
|
||||||
break
|
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
|
Class decorator that converts a normal class into an :class:`Enum`. No
|
||||||
safety checks are done, and some advanced behavior (such as
|
safety checks are done, and some advanced behavior (such as
|
||||||
:func:`__init_subclass__`) is not available. Enum creation can be faster
|
: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
|
>>> from enum import Enum, _simple_enum
|
||||||
>>> @_simple_enum(Enum)
|
>>> @_simple_enum(Enum)
|
||||||
|
|
|
@ -171,7 +171,7 @@ class TestHelpers(unittest.TestCase):
|
||||||
|
|
||||||
sunder_names = '_bad_', '_good_', '_what_ho_'
|
sunder_names = '_bad_', '_good_', '_what_ho_'
|
||||||
dunder_names = '__mal__', '__bien__', '__que_que__'
|
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_'
|
private_and_sunder_names = '_MyEnum__private_', '_MyEnum__also_private_'
|
||||||
random_names = 'okay', '_semi_private', '_weird__', '_MyEnum__'
|
random_names = 'okay', '_semi_private', '_weird__', '_MyEnum__'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue