-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Instantiating enum with invalid value results in ValueError twice #83909
Comments
Trying to instantiate an enum with an invalid value results in "During handling of the above exception, another exception occurred:". $ cat > test.py << EOF
from enum import Enum class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
Color(0)
EOF $ python --version
Python 3.8.1
$ python test.py
ValueError: 0 is not a valid Color During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 8, in <module>
Color(0)
File "/usr/lib/python3.8/enum.py", line 304, in __call__
return cls.__new__(cls, value)
File "/usr/lib/python3.8/enum.py", line 595, in __new__
raise exc
File "/usr/lib/python3.8/enum.py", line 579, in __new__
result = cls._missing_(value)
File "/usr/lib/python3.8/enum.py", line 608, in _missing_
raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 0 is not a valid Color I think this might be related to 019f0a0 ("bpo-34536: raise error for invalid _missing_ results (GH-9147)"), but I haven't been able to confirm. |
I can't reproduce this on the latest python (3.9) from master. Can you? |
Never mind, I was able to reproduce it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ValueError
#22277ValueError
(GH-22277) #22282ValueError
(GH-22277) #22283Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: