diff options
| author | Ethan Furman <ethan@stoneleaf.us> | 2023-09-08 01:19:03 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-08 01:19:03 (GMT) |
| commit | c74e440168fab9bf91346471087a394af13fa2db (patch) | |
| tree | e9afe2d0f55fff41ed232a524b6ef76694dc76b2 /Lib/enum.py | |
| parent | b9831e5c98de280870b6d932033b868ef56fa2fa (diff) | |
| download | cpython-c74e440168fab9bf91346471087a394af13fa2db.zip cpython-c74e440168fab9bf91346471087a394af13fa2db.tar.gz cpython-c74e440168fab9bf91346471087a394af13fa2db.tar.bz2 | |
gh-109022: [Enum] require `names=()` to create empty enum type (GH-109048)
add guard so that ``Enum('bar')`` raises a TypeError instead of
creating a new enum class called `bar`. To create the new but
empty class, use:
huh = Enum('bar', names=())
Diffstat (limited to 'Lib/enum.py')
| -rw-r--r-- | Lib/enum.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index 4b99e7b..994a7b9 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -730,6 +730,11 @@ class EnumType(type): 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: + # 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, |
