GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Meaning of tracebacklimit differs between sys.tracebacklimit and traceback module · Issue #82378 · python/cpython

Meaning of tracebacklimit differs between sys.tracebacklimit and traceback module #82378

New issue
Copy link
New issue
Copy link
Closed
Closed
Meaning of tracebacklimit differs between sys.tracebacklimit and traceback module#82378
Copy link
Labels
3.10 (EOL)end of lifeend of life3.13only security fixesonly security fixes3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetopic-replRelated to the interactive shellRelated to the interactive shell

Description

cfbolz
mannequin
opened on Sep 17, 2019
Issue body actions
BPO 38197
Nosy @cfbolz, @iritkatriel
Files
  • x.py
  • 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 = None
    closed_at = None
    created_at = <Date 2019-09-17.10:34:55.146>
    labels = ['3.8', '3.9', '3.10']
    title = 'Meaning of tracebacklimit differs between sys.tracebacklimit and traceback module'
    updated_at = <Date 2020-11-04.19:48:39.522>
    user = 'https://github.com/cfbolz'

    bugs.python.org fields:

    activity = <Date 2020-11-04.19:48:39.522>
    actor = 'Carl.Friedrich.Bolz'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2019-09-17.10:34:55.146>
    creator = 'Carl.Friedrich.Bolz'
    dependencies = []
    files = ['48610']
    hgrepos = []
    issue_num = 38197
    keywords = []
    message_count = 3.0
    messages = ['352628', '380352', '380355']
    nosy_count = 2.0
    nosy_names = ['Carl.Friedrich.Bolz', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue38197'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    Linked PRs

    • gh-82378: fix sys.tracebacklimit in pyrepl #122452
    • gh-82378 fix sys.tracebacklimit in pyrepl #123062
    • [3.13] gh-82378 fix sys.tracebacklimit in pyrepl (GH-123062) #123252
    • gh-82378: document the difference between sys.tracebacklimit and the limit arguments #123286
    • [3.13] gh-82378: Document the difference between sys.tracebacklimit and the limit arguments (GH-123286) #123325
    • [3.12] gh-82378: Document the difference between sys.tracebacklimit and the limit arguments (GH-123286) #123326

    Activity

    Next
    1. cfbolz commented on Sep 17, 2019

      @cfbolz
      cfbolzmannequin
      on Sep 17, 2019
      MannequinAuthor
      More actions

      The meaning of sys.tracebacklimit seems to be different than the meaning of the various limit parameters in the traceback module. One shows the top n stack frames, the other the bottom n.

      Is this intentional, and if yes, is that difference documented somewhere? (it came up because PyPy just uses the traceback module and has no equivalent of PyTraceBack_Print).

      See the attached script to understand the problem. The script formats the same exception twice, once with the traceback module, once by the interpreter. I would have expected them to look the same for all limits, but instead:

      $ ./python /tmp/x.py 3
      limit 3
      from traceback module:
      Traceback (most recent call last):
        File "/tmp/x.py", line 19, in <module>
          main()
        File "/tmp/x.py", line 16, in main
          x3()
        File "/tmp/x.py", line 14, in x3
          x2()
      ZeroDivisionError: division by zero
      
      from interpreter:
      Traceback (most recent call last):
        File "/tmp/x.py", line 14, in x3
          x2()
        File "/tmp/x.py", line 12, in x2
          x1()
        File "/tmp/x.py", line 10, in x1
          1 / 0
      ZeroDivisionError: division by zero
    2. cfbolz
      added
      3.7 (EOL)end of lifeend of life
      on Sep 17, 2019
    3. iritkatriel commented on Nov 4, 2020

      @iritkatriel
      iritkatriel
      on Nov 4, 2020
      Member
      More actions

      If you change your script to do
      sys.tracebacklimit = abs(limit)
      and run it with arg -3, then you get the output you expect:

      C:\Users\User\src\cpython>python.bat x.py -3
      Running Release|Win32 interpreter...
      limit -3
      from traceback module:
      Traceback (most recent call last):
        File "C:\Users\User\src\cpython\x.py", line 14, in x3
          x2()
        File "C:\Users\User\src\cpython\x.py", line 12, in x2
          x1()
        File "C:\Users\User\src\cpython\x.py", line 10, in x1
          1 / 0
      ZeroDivisionError: division by zero
      
      from interpreter:
      Traceback (most recent call last):
        File "C:\Users\User\src\cpython\x.py", line 14, in x3
          x2()
        File "C:\Users\User\src\cpython\x.py", line 12, in x2
          x1()
        File "C:\Users\User\src\cpython\x.py", line 10, in x1
          1 / 0
      ZeroDivisionError: division by zero

      The documentation for traceback mentions the possibility of using negative limits and their meaning:

      Print up to limit stack trace entries from traceback object tb (starting from the caller’s frame) if limit is positive. Otherwise, print the last abs(limit) entries.

      https://docs.python.org/3/library/traceback.html#traceback.print_tb

    4. iritkatriel
      added
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      3.10 (EOL)end of lifeend of life
      and removed
      3.7 (EOL)end of lifeend of life
      on Nov 4, 2020
    5. cfbolz commented on Nov 4, 2020

      @cfbolz
      cfbolzmannequin
      on Nov 4, 2020
      MannequinAuthor
      More actions

      It's still inconsistent between the two ways to get a traceback, and the inconsistency is not documented.

    6. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    7. cfbolz commented on Jul 29, 2024

      @cfbolz
      cfbolz
      on Jul 29, 2024
      ContributorAuthor
      More actions

      This issue also becomes more relevant now, with pyrepl using code, which uses the traceback module. Here's a behaviour difference between cpy3.12 and cpy3.13 (current 3.13 branch):

      cfbolz@triacontahedron:~/projects/cpython$ cat x.py 
      def x1():
          1 / 0
      def x2():
          x1()
      def x3():
          x2()
      cfbolz@triacontahedron:~/projects/cpython$ python3.12 -i x.py
      >>> x3()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/home/cfbolz/projects/cpython/x.py", line 6, in x3
          x2()
        File "/home/cfbolz/projects/cpython/x.py", line 4, in x2
          x1()
        File "/home/cfbolz/projects/cpython/x.py", line 2, in x1
          1 / 0
          ~~^~~
      ZeroDivisionError: division by zero
      >>> import sys
      >>> sys.tracebacklimit = 2
      >>> x3()
      Traceback (most recent call last):
        File "/home/cfbolz/projects/cpython/x.py", line 4, in x2
          x1()
        File "/home/cfbolz/projects/cpython/x.py", line 2, in x1
          1 / 0
          ~~^~~
      ZeroDivisionError: division by zero
      >>> 
      cfbolz@triacontahedron:~/projects/cpython$ ./python -i x.py 
      >>> x3()
      Traceback (most recent call last):
        File "<python-input-0>", line 1, in <module>
          x3()
          ~~^^
        File "/home/cfbolz/projects/cpython/x.py", line 6, in x3
          x2()
          ~~^^
        File "/home/cfbolz/projects/cpython/x.py", line 4, in x2
          x1()
          ~~^^
        File "/home/cfbolz/projects/cpython/x.py", line 2, in x1
          1 / 0
          ~~^~~
      ZeroDivisionError: division by zero
      >>> import sys
      >>> sys.tracebacklimit = 2
      >>> x3()
      Traceback (most recent call last):
        File "<python-input-3>", line 1, in <module>
          x3()
          ~~^^
        File "/home/cfbolz/projects/cpython/x.py", line 6, in x3
          x2()
          ~~^^
      ZeroDivisionError: division by zero
      >>> 
      

      note how on 3.12 the traceback is missing the frame for x3 when sys.tracebacklimit is set, and 3.13 is missing the frame for x1.

      I would still argue that sys.tracebacklimit has basically been broken since essentially forever in the traceback module. It might still be too late to fix this, of course, because people have come to rely on this undocumented behavior.

    8. cfbolz
      added
      topic-replRelated to the interactive shellRelated to the interactive shell
      3.13only security fixesonly security fixes
      on Jul 29, 2024
    9. iritkatriel commented on Jul 29, 2024

      @iritkatriel
      iritkatriel
      on Jul 29, 2024
      Member
      More actions

      I would still argue that sys.tracebacklimit has basically been broken since essentially forever in the traceback module. It might still be too late to fix this, of course, because people have come to rely on this undocumented behavior.

      Yes, we'd need to add a new limit and deprecate this one.

    10. cfbolz commented on Jul 29, 2024

      @cfbolz
      cfbolz
      on Jul 29, 2024
      ContributorAuthor
      More actions

      Ok, but that means we still have a very clear behavior change in the repl from 3.12 to 3.13 if someone is setting sys.tracebacklimit

    11. iritkatriel commented on Jul 29, 2024

      @iritkatriel
      iritkatriel
      on Jul 29, 2024
      Member
      More actions

      CC @pablogsal @ambv re repl.

    12. 10 remaining items

    13. cfbolz
      added a commit that references this issue on Aug 23, 2024

      [3.13] pythongh-82378 fix sys.tracebacklimit in pyrepl, approach 2 (p…

      b847597
    14. pablogsal
      added a commit that references this issue on Aug 23, 2024

      [3.13] gh-82378 fix sys.tracebacklimit in pyrepl, approach 2 (GH-123062…

      0955db1
    15. pablogsal commented on Aug 23, 2024

      @pablogsal
      pablogsal
      on Aug 23, 2024
      Member
      More actions

      Ok, I think we are done with this one. Thanks @cfbolz for the PRs and @serhiy-storchaka for the reviews!

    16. pablogsal
      closed this as completedon Aug 23, 2024
    17. cfbolz commented on Aug 23, 2024

      @cfbolz
      cfbolz
      on Aug 23, 2024
      ContributorAuthor
      More actions

      @pablogsal I kind of would like to still add a paragraph to the traceback module docs somewhere that mentions the differences between the meaning of limit in that module and the meaning of sys.tracebacklimit. I just don't quite know where in the page to put it. Maybe simply in the text after print_tb where the meaning of limit is explained for the first time?

      I'll re-open the issue to make sure I don't forget (or should I open a new one for the doc change?).

    18. cfbolz
      reopened this on Aug 23, 2024
    19. pablogsal commented on Aug 23, 2024

      @pablogsal
      pablogsal
      on Aug 23, 2024
      Member
      More actions

      or should I open a new one for the doc change?

      No, we can reuse this one 👍

      Maybe simply in the text after print_tb where the meaning of limit is explained for the first time?

      I think that would be a good place. Alternatively we can add it at the start after the "The module defines the following functions:
      " as a note

    20. cfbolz
      added a commit that references this issue on Aug 24, 2024

      pythongh-82378: document the difference between sys.tracebacklimit an…

      6acd7d7
    21. pablogsal
      added a commit that references this issue on Aug 25, 2024

      gh-82378: Document the difference between sys.tracebacklimit and the …

      70bfef5
    22. miss-islington
      added 3 commits that reference this issue on Aug 25, 2024

      pythongh-82378: Document the difference between sys.tracebacklimit an…

      6c52b1d

      pythongh-82378: Document the difference between sys.tracebacklimit an…

      50260e9

      pythongh-82378: Document the difference between sys.tracebacklimit an…

      5ee8962
    23. pablogsal
      closed this as completedon Aug 25, 2024
    24. pablogsal
      added 2 commits that reference this issue on Aug 25, 2024

      [3.12] gh-82378: Document the difference between sys.tracebacklimit a…

      ffa282c

      [3.13] gh-82378: Document the difference between sys.tracebacklimit a…

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

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifeend of life3.13only security fixesonly security fixes3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetopic-replRelated to the interactive shellRelated to the interactive shell

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.