-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meaning of tracebacklimit differs between sys.tracebacklimit and traceback module #82378
Comments
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 |
If you change your script to do 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 |
It's still inconsistent between the two ways to get a traceback, and the inconsistency is not documented. |
This issue also becomes more relevant now, with pyrepl using
note how on 3.12 the traceback is missing the frame for I would still argue that |
Yes, we'd need to add a new limit and deprecate this one. |
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 |
CC @pablogsal @ambv re repl. |
ah, I see that @pablogsal already had to work around this problem in |
make sure that pyrepl uses the same logic for sys.tracebacklimit as both the basic repl and the standard sys.excepthook
Make sure that pyrepl uses the same logic for sys.tracebacklimit as both the basic repl and the standard sys.excepthook
…ythonGH-123062) Make sure that pyrepl uses the same logic for sys.tracebacklimit as both the basic repl and the standard sys.excepthook (cherry picked from commit 63603bc) Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
…23062) Make sure that pyrepl uses the same logic for sys.tracebacklimit as both the basic repl and the standard sys.excepthook
…23062) Make sure that pyrepl uses the same logic for sys.tracebacklimit as both the basic repl and the standard sys.excepthook
…ythonGH-123062) Make sure that pyrepl uses the same logic for sys.tracebacklimit as both the basic repl and the standard sys.excepthook (cherry picked from commit 63603bc) Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
…ythonGH-123062) Make sure that pyrepl uses the same logic for sys.tracebacklimit as both the basic repl and the standard sys.excepthook (cherry picked from commit 63603bc) Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
Ok, I think we are done with this one. Thanks @cfbolz for the PRs and @serhiy-storchaka for the reviews! |
@pablogsal I kind of would like to still add a paragraph to the I'll re-open the issue to make sure I don't forget (or should I open a new one for the doc change?). |
No, we can reuse this one 👍
I think that would be a good place. Alternatively we can add it at the start after the "The module defines the following functions: |
…d the limit arguments
…d the limit arguments (pythonGH-123286) (cherry picked from commit 70bfef5) Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
…d the limit arguments (pythonGH-123286) (cherry picked from commit 70bfef5) Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
…d the limit arguments (pythonGH-123286) (cherry picked from commit 70bfef5) Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
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:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: