-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-43656: Introduce format_locals in traceback #29299
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
Conversation
This allows customization of the string representation of the locals of stack frames. Also, remind users that __repr__ shouldn't raise.
def f(): | ||
1/0 | ||
|
||
def g(): | ||
try: | ||
f() | ||
except: | ||
return sys.exc_info() | ||
def g(): | ||
try: | ||
f() | ||
except: | ||
return sys.exc_info() | ||
|
||
exc_info = g() | ||
exc_info = g() | ||
|
||
class Skip_G(traceback.StackSummary): | ||
def format_frame_summary(self, frame_summary): | ||
if frame_summary.name == 'g': | ||
return None | ||
return super().format_frame_summary(frame_summary) | ||
class Skip_G(traceback.StackSummary): | ||
def format_frame_summary(self, frame_summary): | ||
if frame_summary.name == 'g': | ||
return None | ||
return super().format_frame_summary(frame_summary) | ||
|
||
stack = Skip_G.extract( | ||
traceback.walk_tb(exc_info[2])).format() | ||
stack = Skip_G.extract( | ||
traceback.walk_tb(exc_info[2])).format() | ||
|
||
self.assertEqual(len(stack), 1) | ||
lno = f.__code__.co_firstlineno + 1 | ||
self.assertEqual( | ||
stack[0], | ||
f' File "{__file__}", line {lno}, in f\n 1/0\n' | ||
) | ||
self.assertEqual(len(stack), 1) | ||
lno = f.__code__.co_firstlineno + 1 | ||
self.assertEqual( | ||
stack[0], | ||
f' File "{__file__}", line {lno}, in f\n 1/0\n' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cosmetic change was done by make patchcheck
Irit Katriel:
|
This allows customization of the string representation of the locals of stack frames.
Also, remind users that repr shouldn't raise.
https://bugs.python.org/issue43656