gh-110905: [Enum] minor fixes and cleanup (GH-110906)

This commit is contained in:
Pieter Eendebak 2023-10-16 22:37:54 +02:00 committed by GitHub
parent f07ca27709
commit a77180e663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View File

@ -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)

View File

@ -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__'