Skip to content

traceback.py: Allow customization of per-frame line formatting in StackSummary #88735

Closed

Description

@ammaraskar
BPO 44569
Nosy @terryjreedy, @ammaraskar, @pablogsal, @isidentical
PRs
  • bpo-44569: Decouple frame formatting in traceback.py #27038
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ammaraskar'
    closed_at = <Date 2021-07-16.12:21:24.792>
    created_at = <Date 2021-07-05.16:47:05.034>
    labels = ['library', '3.11']
    title = 'traceback.py: Allow customization of per-frame line formatting in StackSummary'
    updated_at = <Date 2021-07-16.12:21:24.930>
    user = 'https://github.com/ammaraskar'

    bugs.python.org fields:

    activity = <Date 2021-07-16.12:21:24.930>
    actor = 'pablogsal'
    assignee = 'ammar2'
    closed = True
    closed_date = <Date 2021-07-16.12:21:24.792>
    closer = 'pablogsal'
    components = ['Library (Lib)']
    creation = <Date 2021-07-05.16:47:05.034>
    creator = 'ammar2'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44569
    keywords = ['patch']
    message_count = 2.0
    messages = ['397009', '397616']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'ammar2', 'pablogsal', 'BTaskaya']
    pr_nums = ['27038']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44569'
    versions = ['Python 3.11']

    Activity

    1. ammaraskar commented on Jul 5, 2021

      @ammaraskar
      MemberAuthor

      During the implementation of PEP-657, Terry Jan Reedy pointed out that in the format method of traceback.StackSummary there are two roles being fulfilled, there is some logic to handle omitting repeated lines involved in recursive calls and then the core per-frame formatting logic:

      cpython/Lib/traceback.py

      Lines 484 to 503 in 17f94e2

      row = []
      row.append(' File "{}", line {}, in {}\n'.format(
      frame.filename, frame.lineno, frame.name))
      if frame.line:
      row.append(' {}\n'.format(frame.line.strip()))
      stripped_characters = len(frame._original_line) - len(frame.line.lstrip())
      if frame.end_lineno == frame.lineno and frame.end_colno != 0:
      colno = _byte_offset_to_character_offset(frame._original_line, frame.colno)
      end_colno = _byte_offset_to_character_offset(frame._original_line, frame.end_colno)
      row.append(' ')
      row.append(' ' * (colno - stripped_characters))
      row.append('^' * (end_colno - colno))
      row.append('\n')
      if frame.locals:
      for name, value in sorted(frame.locals.items()):
      row.append(' {name} = {value}\n'.format(name=name, value=value))
      result.append(''.join(row))

      To allow the per-line formatting to be overridden easily, these lines should be split into a separate method.

    2. self-assigned this
      on Jul 5, 2021
    3. added
      stdlibStandard Library Python modules in the Lib/ directory
      3.11only security fixes
      on Jul 5, 2021
    4. self-assigned this
      on Jul 5, 2021
    5. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jul 5, 2021
    6. pablogsal commented on Jul 16, 2021

      @pablogsal
      Member

      New changeset 8ce3008 by Ammar Askar in branch 'main':
      bpo-44569: Decouple frame formatting in traceback.py (GH-27038)
      8ce3008

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.11only security fixesstdlibStandard Library Python modules in the Lib/ directory

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions