-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weird error when using enum(val1, val2) #107878
Comments
The error message is correct. def __call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1):
"""
Either returns an existing member, or creates a new enum class.
This method is used both when an enum class is given a value to match
to an enumeration member (i.e. Color(3)) and for the functional API
(i.e. Color = Enum('Color', names='RED GREEN BLUE')).
When used for the functional API:
`value` will be the name of the new class.
`names` should be either a string of white-space/comma delimited names
(values will start at `start`), or an iterator/mapping of name, value pairs.
...
"""
if names is None: # simple value lookup
return cls.__new__(cls, value)
# otherwise, functional API: we're creating a new Enum type
return cls._create_(value, names, ...) According to the doc, subclassing an enumeration is allowed only if the enumeration does not define any members. So in enum.py line930 it raised the error. |
I see that, but it's a leaky abstraction. |
This is fixed in 3.13:
|
Right, apologies for not checking |
Using the example from the docs:
Actual output (py 3.11):
Expected output- not 100% sure but, something along the lines of:
TypeError
saying "... takes 1 positional argument but 2 were given" likeColor()
does, orValueError
saying "... is not a valid Color" likeColor(0)
doesThe current metaclass error message is a bit confusing.
The text was updated successfully, but these errors were encountered: