mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
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:
parent
0dca5eb54b
commit
ec09973f5b
3 changed files with 30 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue