bpo-43744: [Enum] fix `_is_private` (GH-25349)

``_is_private`` now returns ``False`` instead of raising an exception when enum name matches beginning of class name
as used in a private variable
This commit is contained in:
Ethan Furman 2021-04-15 06:58:33 -07:00 committed by GitHub
parent 0dca5eb54b
commit ec09973f5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View file

@ -53,10 +53,11 @@ def _is_sunder(name):
def _is_private(cls_name, name):
# do not use `re` as `re` imports `enum`
pattern = '_%s__' % (cls_name, )
pat_len = len(pattern)
if (
len(name) >= 5
len(name) > pat_len
and name.startswith(pattern)
and name[len(pattern)] != '_'
and name[pat_len:pat_len+1] != ['_']
and (name[-1] != '_' or name[-2] != '_')
):
return True