-
-
Notifications
You must be signed in to change notification settings - Fork 32k
traceback._compute_suggestion_error crashes on __getattr__
raising
#129605
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
Comments
A quick fix (I'm not sure it's a right way): diff --git a/Lib/traceback.py b/Lib/traceback.py
index 31c73efcef..abcc099c29 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -1520,8 +1520,11 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
# has the wrong name as attribute
if 'self' in frame.f_locals:
self = frame.f_locals['self']
- if hasattr(self, wrong_name):
- return f"self.{wrong_name}"
+ try:
+ if hasattr(self, wrong_name):
+ return f"self.{wrong_name}"
+ except NameError:
+ pass
try:
import _suggestions >>> b.pepe
pepe
qq
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
b.pepe
File "<python-input-0>", line 4, in __getattr__
print(qq)
^^
NameError: name 'qq' is not defined |
Cool, but "qq" should not be searched in the class. Notice that |
That might be helpful for suggestions, see 99e2e60. |
Another instance of the same error:
gives (at least on Python 3.12):
so the property gets re-executed. In other cases this can also lead to an infinite chain of exceptions. |
__getattr__
raising
I encountered this bug when trying to log such an exception using The following code demonstrates the issue (using import logging
class Foo:
@property
def x(self):
raise ValueError("x")
def y(self):
return x
logger = logging.getLogger(__name__)
try:
Foo().y()
except Exception as e:
logger.exception("y failed") # raises!
print("done") # not reached!
I think this should be considered a bug in |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
This is a regression introduced in 3.13 because the new pyrepl. 3.14 is also affected.
Type this in an interactive 3.13/3.14 session:
And the interactive python session is terminated.
Under previous Python releases, with no pyrepl, the right exception is raised and the repl keeps going:
Notice that this problem raises SPECIFICALLY if
__getattr__
raises a NameError exception. Other exceptions, like division by zero, don't break pyrepl.CPython versions tested on:
3.13, 3.12, 3.11, 3.10, 3.9, 3.14
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: