summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2024-03-07 21:30:26 (GMT)
committerGitHub <noreply@github.com>2024-03-07 21:30:26 (GMT)
commit13ffd4bd9f529b6a5fe33741fbd57f14b4b80137 (patch)
tree78bdbc78cfc78e8fb584db32d0c082ed68a9a721 /Lib/enum.py
parentb2d74cdbcd0b47bc938200969bb31e5b37dc11e1 (diff)
downloadcpython-13ffd4bd9f529b6a5fe33741fbd57f14b4b80137.zip
cpython-13ffd4bd9f529b6a5fe33741fbd57f14b4b80137.tar.gz
cpython-13ffd4bd9f529b6a5fe33741fbd57f14b4b80137.tar.bz2
gh-116040: [Enum] fix by-value calls when second value is falsey; e.g. Cardinal(1, 0) (GH-116072)
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 22963cc..3499cb0 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -162,6 +162,13 @@ def _dedent(text):
lines[j] = l[i:]
return '\n'.join(lines)
+class _not_given:
+ def __repr__(self):
+ return('<not given>')
+ def __bool__(self):
+ return False
+_not_given = _not_given()
+
class _auto_null:
def __repr__(self):
return '_auto_null'
@@ -680,7 +687,7 @@ class EnumType(type):
"""
return True
- def __call__(cls, value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None):
+ def __call__(cls, value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None):
"""
Either returns an existing member, or creates a new enum class.
@@ -709,18 +716,18 @@ class EnumType(type):
"""
if cls._member_map_:
# simple value lookup if members exist
- if names:
+ if names is not _not_given:
value = (value, names) + values
return cls.__new__(cls, value)
# otherwise, functional API: we're creating a new Enum type
- if names is None and type is None:
+ if names is _not_given and type is None:
# no body? no data-type? possibly wrong usage
raise TypeError(
f"{cls} has no members; specify `names=()` if you meant to create a new, empty, enum"
)
return cls._create_(
class_name=value,
- names=names,
+ names=names or None,
module=module,
qualname=qualname,
type=type,