bpo-43656: Introduce format_locals in traceback#29299
bpo-43656: Introduce format_locals in traceback#29299moi90 wants to merge 7 commits intopython:mainpython/cpython:mainfrom
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.
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