diff options
author | Brennan D Baraban <34765317+bdbaraban@users.noreply.github.com> | 2019-03-03 22:09:11 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-03-03 22:09:11 (GMT) |
commit | 8b914d2767acba3a9e78f1dacdc2d61dbfd7e304 (patch) | |
tree | a06002f1635e1b5d312451509075fb3ea9cb03aa /Lib/enum.py | |
parent | 8b50400fbe607ef558d6c0033efa697c99417507 (diff) | |
download | cpython-8b914d2767acba3a9e78f1dacdc2d61dbfd7e304.zip cpython-8b914d2767acba3a9e78f1dacdc2d61dbfd7e304.tar.gz cpython-8b914d2767acba3a9e78f1dacdc2d61dbfd7e304.tar.bz2 |
bpo-35899: Fix Enum handling of empty and weird strings (GH-11891)
Co-authored-by: Maxwell <maxwellpxt@gmail.com>
Co-authored-by: Stéphane Wirtel <stephane@wirtel.be>
https://bugs.python.org/issue35899
Diffstat (limited to 'Lib/enum.py')
-rw-r--r-- | Lib/enum.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index a958ed8..6ef17c7 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -19,18 +19,19 @@ def _is_descriptor(obj): def _is_dunder(name): """Returns True if a __dunder__ name, False otherwise.""" - return (name[:2] == name[-2:] == '__' and - name[2:3] != '_' and - name[-3:-2] != '_' and - len(name) > 4) + return (len(name) > 4 and + name[:2] == name[-2:] == '__' and + name[2] != '_' and + name[-3] != '_') def _is_sunder(name): """Returns True if a _sunder_ name, False otherwise.""" - return (name[0] == name[-1] == '_' and + return (len(name) > 2 and + name[0] == name[-1] == '_' and name[1:2] != '_' and - name[-2:-1] != '_' and - len(name) > 2) + name[-2:-1] != '_') + def _make_class_unpicklable(cls): """Make the given class un-picklable.""" @@ -150,7 +151,7 @@ class EnumMeta(type): _order_ = classdict.pop('_order_', None) # check for illegal enum names (any others?) - invalid_names = set(enum_members) & {'mro', } + invalid_names = set(enum_members) & {'mro', ''} if invalid_names: raise ValueError('Invalid enum member name: {0}'.format( ','.join(invalid_names))) |