-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
3.10a5 regression: AttributeError: 'NoneType' object has no attribute '__suppress_context__' in traceback.py #87312
Comments
After upgrading to 3.10a5, calling logging.exception("test") results in:
Traceback (most recent call last):
File "/usr/lib/python3.10/logging/__init__.py", line 1094, in emit
msg = self.format(record)
File "/usr/lib/python3.10/logging/__init__.py", line 938, in format
return fmt.format(record)
File "/usr/lib/python3.10/logging/__init__.py", line 682, in format
record.exc_text = self.formatException(record.exc_info)
File "/usr/lib/python3.10/logging/__init__.py", line 632, in formatException
traceback.print_exception(ei[0], ei[1], tb, None, sio)
File "/usr/lib/python3.10/traceback.py", line 113, in print_exception
te = TracebackException(type(value), value, tb, limit=limit, compact=True)
File "/usr/lib/python3.10/traceback.py", line 531, in __init__
need_context = cause is None and not e.__suppress_context__
AttributeError: 'NoneType' object has no attribute '__suppress_context__' That method is documented as "This function should only be called from an exception handler.", but the same also happens when e.g. calling traceback.print_exc() (without a current exception) or traceback.print_exception(None, None, None). Both worked fine before 3.10 Alpha 5, the code seems to do None-checks in other places, and typeshed also marks those arguments as Optional. |
Thanks, I’ll add the None check. |
There's another such issue due to PR 22610 // bpo-26389: >>> traceback.format_exception(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\User\src\cpython-dev\lib\traceback.py", line 128, in format_exception
value, tb = _parse_value_tb(exc, value, tb)
File "C:\Users\User\src\cpython-dev\lib\traceback.py", line 94, in _parse_value_tb
return exc, exc.__traceback__
AttributeError: 'NoneType' object has no attribute '__traceback__' |
Marking as blocker because these are 3.10 regressions. |
It seems to me that print_exception(None), etc, *should* raise something. Printing "NoneType: None\n" makes no sense to me since NoneType is not an exception. In 3.9, it raised TypeError for # of arguments. I do note that in 3.9
>>> traceback.print_exception(None, None, None)
NoneType: None I wonder what the rationale was. It isn't because these functions never raise. |
In 3.9 you had to give exc,val,tb. In 3.10 the shortcut was added. bpo-26389. |
JFYI, there are 2 affected Fedora packages (that we know of): visidata fails to build with Python 3.10: AttributeError: 'NoneType' object has no attribute '__suppress_context__' python-utils fails to build with Python 3.10: AttributeError: 'NoneType' object has no attribute '__suppress_context__' |
I think it's because sys.exc_info() can return None, None, None when there is no exceptions. |
Let's split the print_exception(None) case (new issue) from the regression. I've updated the PR to fix only the latter, which is not controversial. I don't know what print_exception(None) should do. |
Are you going to create a separate PR or a new issue for the other thing? (And what exactly *is* the other thing? Please summarize.) |
The other thing is not related to the one reported here, but I found it while writing the test for this. We have a new API in 3.10, where you can do traceback.print_exception(ex) (so you don't need to give the whole type,val,tb triplet). But: >>> traceback.print_exception(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\User\src\cpython-dev\lib\traceback.py", line 110, in print_exception
value, tb = _parse_value_tb(exc, value, tb)
File "C:\Users\User\src\cpython-dev\lib\traceback.py", line 94, in _parse_value_tb
return exc, exc.__traceback__
AttributeError: 'NoneType' object has no attribute '__traceback__' |
So the PR just merged fixes that, right? Color me confused. |
The PR just merged fixes the issue that was reported by Florian (what I broke). That impacted pre-3.10 APIs so was an actual regression. The issue with traceback.print_exception(None) is new to 3.10, and was introduced in bpo-26389. |
So the remaining question is what to do for print_exception(None)? Honestly |
Yes.
That's not the current behaviour - I removed that fix from the PR till we agree what to do. Currently we get the AttributeError. |
The new PR makes it print |
Note: 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: