mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
[3.12] gh-109022: [Enum] require names=()
to create empty enum type (GH-109048) (#109122)
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=())
(cherry picked from commit c74e440168
)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
parent
d533ab17ec
commit
ca848bbf78
3 changed files with 14 additions and 4 deletions
|
@ -739,6 +739,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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue