summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2021-04-15 13:58:33 (GMT)
committerGitHub <noreply@github.com>2021-04-15 13:58:33 (GMT)
commitec09973f5b21d33550c834ddc89606b0e1c70ffd (patch)
tree21d1545868a0d3be55a76ed88f6514941aab74fc /Lib/enum.py
parent0dca5eb54bd137ed5c6e20012fe8dddb2eadfdd7 (diff)
downloadcpython-ec09973f5b21d33550c834ddc89606b0e1c70ffd.zip
cpython-ec09973f5b21d33550c834ddc89606b0e1c70ffd.tar.gz
cpython-ec09973f5b21d33550c834ddc89606b0e1c70ffd.tar.bz2
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
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 9533dd8..17deb4b 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -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