-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Behaviour of unformattable ValueError
on list.index
has changed in Python 3.11 (change in PyErr_Format)
#112768
Comments
ValueError
on list.index
has changed in Python 3.11 (change in PyErr_Format)ValueError
on list.index
has changed in Python 3.11 (change in PyErr_Format)
Yes, it is a deliberate change. If Cython crashes because of this, it has bugs, and this change helped to expose them. |
I mostly agree with this, and have a fix for the Cython issue that will be applied whatever you decide to do with this. If I were designing this I'd probably treat the first exception as the "main error", and any exception from generating the format string as "unraisable". Just because the error message attached to the exception feels like it could be treated as optional compared to the exception itself. However, just wanted to flag that there's a behavioural change that isn't too hard to hit - I don't think it's too uncommon for |
Would it be possible to print a double traceback, as in somewhat similar situations? (The following is not exact.)
|
No, it is unreasonable. Another exception occurred before the intended exception was created, so the intended exception cannot be raised. Look at the following example: raise ValueError(1/0) There is no way to get a ValueError instead or in addition to a ZeroDivisionError in a traceback. ValueError cannot be created, because its argument cannot be evaluated. Creation of exception with wrong argument is a bug, because the exception argument can matter. And an exception raised when calculate exception arguments (for example KeyboardInterrupt, MemoryError or RecursionError which can be raised by virtually any code) does matter and should not be silenced. |
Bug report
Bug description:
On Python 3.10 this prints
On Python 3.11 this prints
When
PyErr_Format
fails in current versions of Python, it doesn't set the exception and instead raises the new one:cpython/Python/errors.c
Lines 1162 to 1167 in 11d88a1
In earlier versions of Python it used to raise the requested exception unconditionally
cpython/Python/errors.c
Lines 1059 to 1064 in b6535ea
This looks to have been a deliberate change but it can affect the behaviour of real code (cython/cython#5894). Interestingly PyPy got there before you with this behaviour (https://foss.heptapod.net/pypy/pypy/-/issues/3978)
CPython versions tested on:
3.11
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: