-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
do_raise()
doesn't make sure the constructed cause is an exception.
#112217
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
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
type-bug
An unexpected behavior, bug, or error
Comments
do_raise()
doesn't make sure the constructed cause is an exception.
iritkatriel
pushed a commit
that referenced
this issue
Nov 27, 2023
@iritkatriel Please apply the "needs backport" labels to the PR (#112216) if we need to backport this. Thanks! |
Let's not backport. I don't think it will merge cleanly in the previous versions and this bug is not worth the risk of a manual backport. |
aisk
pushed a commit
to aisk/cpython
that referenced
this issue
Feb 11, 2024
Glyphack
pushed a commit
to Glyphack/cpython
that referenced
this issue
Sep 2, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
type-bug
An unexpected behavior, bug, or error
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
Consider the following:
In
Python/ceval.c
, indo_raise()
, when you raise an object, cpython checks if it's an exception type, and if it is, constructs it by calling it with no arguments. Then it checks to make sure that what was constructed is in fact an exception.Then it does the same thing for the exception's cause. If it's a type, it constructs the cause by calling it with no arguments. But, for the cause, it actually doesn't check to make sure that the result of the call is in fact an exception, it just stores the result without checking. This seems like a bug. Not a catastrophic one by any means, but probably unintentional considering that the very same condition is checked a few lines above.
That doesn't necessarily explain the result above though. We've created an exception object where the cause is
None
(or any other sort of object that we want). Then, when the interpreter (interactive mode) goes to print the exception, it expects the cause to be an exception. This leads to yet another exception being raised, telling you that the cause is the wrong type.The solution of course is just to add the check when the cause is called. I've submitted the pull request, here: #112216
CPython versions tested on:
3.10, 3.11, 3.12, CPython main branch
Operating systems tested on:
Linux, Windows
Linked PRs
do_raise()
where cause is a type. #112216The text was updated successfully, but these errors were encountered: