[New-bugs-announce] [issue39728] Instantiating enum with invalid value results in ValueError twice
Jonas Malaco
report at bugs.python.org
Sun Feb 23 04:07:04 EST 2020
New submission from Jonas Malaco <jonas at protocubo.io>:
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 019f0a0cb85e ("bpo-34536: raise error for invalid _missing_ results (GH-9147)"), but I haven't been able to confirm.
----------
components: Library (Lib)
messages: 362496
nosy: jonasmalaco
priority: normal
severity: normal
status: open
title: Instantiating enum with invalid value results in ValueError twice
type: behavior
versions: Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39728>
_______________________________________
More information about the New-bugs-announce
mailing list