mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
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=())
This commit is contained in:
parent
b9831e5c98
commit
c74e440168
3 changed files with 14 additions and 4 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue