Skip to content

Conversation

methane
Copy link
Member

@methane methane commented Jun 20, 2025

@methane methane requested a review from Copilot June 20, 2025 12:30
@methane methane added type-feature A feature request or enhancement stdlib Standard Library Python modules in the Lib/ directory labels Jun 20, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds two new keyword-only parameters, show_lines and recent_first, to the traceback module’s formatting and printing APIs, allowing callers to suppress source lines or invert traceback order.

  • Introduce show_lines and recent_first across module-level functions and TracebackException/StackSummary methods
  • Update internal printing/formatting logic to pass these flags through
  • Extend tests and documentation to cover new behavior

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Misc/NEWS.d/next/Library/2025-06-20-21-16-32…rst Announce new parameters in the NEWS file
Lib/traceback.py Core implementation: API signatures and logic updates
Lib/test/test_traceback.py New unit tests for show_lines and recent_first flags
Doc/whatsnew/3.15.rst Document what’s new section for show_lines/recent_first
Doc/library/traceback.rst Update function/method docstrings to include new flags
Comments suppressed due to low confidence (4)

Lib/traceback.py:31

  • The first line of the docstring was truncated and now only mentions extract_stack(). It should refer to both extract_tb() and extract_stack(), e.g., "Print the list of tuples as returned by extract_tb() or extract_stack() as a formatted stack trace to the given file."
    extract_stack() as a formatted stack trace to the given file.

Doc/whatsnew/3.15.rst:181

  • [nitpick] Grammar in release notes: replace "It is default to True." with "Defaults to True." for clarity.
  It is default to ``True``.

Doc/library/traceback.rst:125

  • [nitpick] This sentence is duplicated immediately above; remove one instance to avoid redundancy.
   If *show_lines* is false, source code lines are not included in the output.

Doc/library/traceback.rst:175

  • [nitpick] Using "next" as a version string may be confusing. Consider using the actual upcoming version number or a placeholder like "3.x" for clarity.
   .. versionchanged:: next

Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think show_lines should be renamed to something like show_source.

def print(self, *, file=None, chain=True, **kwargs):
def print(self, *, file=None, chain=True, show_lines=True, recent_first=False, **kwargs):
"""Print the result of self.format(chain=chain) to 'file'."""
colorize = kwargs.get("colorize", False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add the new args via **kwargs as was done for colorize? It would save having to update all the signatures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think colorize is in kwargs because of its hidden parameter. Callars determine use COLOR automatically by isatty() and env variables and pass it to here. colorize is not documented.

On the other hand, show_lines and recent_first are explicit parameter.
User need to determine and specify them manually.

Co-authored-by: Hugo van Kemenade <[email protected]>
@methane methane requested a review from AA-Turner as a code owner September 15, 2025 13:55
@methane methane force-pushed the traceback-show_lines branch from 0651ed2 to 2a56c6d Compare September 16, 2025 00:29
@methane methane changed the title gh-135751: traceback: add recent_first and show_lines parameter gh-135751: traceback: add recent_first and show_source_lines Sep 16, 2025
@methane methane force-pushed the traceback-show_lines branch from 9297884 to 94a11de Compare September 16, 2025 10:08
@methane methane force-pushed the traceback-show_lines branch from 94a11de to 2612590 Compare September 16, 2025 10:58
@vstinner
Copy link
Member

Please try to avoid git push --force, it makes reviews harder.

@methane methane requested a review from iritkatriel September 29, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review stdlib Standard Library Python modules in the Lib/ directory type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants