Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-43656: Introduce format_locals in traceback#29299

Closed
moi90 wants to merge 7 commits intopython:mainpython/cpython:mainfrom
moi90:fix-issue-43656moi90/cpython:fix-issue-43656Copy head branch name to clipboard
Closed

bpo-43656: Introduce format_locals in traceback#29299
moi90 wants to merge 7 commits intopython:mainpython/cpython:mainfrom
moi90:fix-issue-43656moi90/cpython:fix-issue-43656Copy head branch name to clipboard

Conversation

@moi90
Copy link
Contributor

@moi90 moi90 commented Oct 28, 2021

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

This allows customization of the string representation of the locals of stack frames.

Also, remind users that __repr__ shouldn't raise.
Comment on lines +1600 to +1625
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'
)
Copy link
Contributor Author

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

@moi90
Copy link
Contributor Author

moi90 commented Nov 25, 2021

Irit Katriel:

While I do think this module should be more customisable than it is, I think it should be done via support for subclassing rather than injecting functions that get forwarded on as you do here.

There are other issues on bpo related to customising this module, with more convincing use cases than suppressing errors. I think it’s more likely that a patch will be accepted which solves the general problem of this module being inflexible (while being backwards compatible).

The patch you propose here solves a small part of the problem while making the api clunkier and it commits us to supporting this new parameter when we try to solve the general problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.