Skip to content

gh-127555: Document that sys.tracebacklimit can be set to None #127556

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

srittau
Copy link
Contributor

@srittau srittau commented Dec 3, 2024

@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news labels Dec 3, 2024
@ZeroIntensity ZeroIntensity added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Dec 3, 2024
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

I don't think this is the intended behavior. The source is here:

if (limitv && PyLong_Check(limitv)) {

Setting to any type that isn't an integer will result in this happening. To me, seeing sys.tracebacklimit = None looks like "no limit," not "default limit." I'm not sure we should document that.

@srittau
Copy link
Contributor Author

srittau commented Dec 3, 2024

Considering that this behavior is explicitly called out in the NEWS entries for 3.6.4 and 3.7.0a3, it sounds deliberate to me.

@ZeroIntensity
Copy link
Member

If we really do want None as a special case, we should emit a warning (or possibly raise an exception) for other types. cc @serhiy-storchaka, who wrote the code.

@serhiy-storchaka
Copy link
Member

Please remember the issue wnd the changelog corresponding to that NEWS entry. I do no remember such issue.

I most likely did not invent that behavior, but simply fixed crashes or error handling in corner cases, or/and synchronized the C and the Python implementations. L9k also at the Python code.

@srittau
Copy link
Contributor Author

srittau commented Dec 3, 2024

For reference, here is the original issue: #76130 and the PR: #4289. The PR introduced an explicit test for None:

check(None, traceback)

@serhiy-storchaka
Copy link
Member

Thanks, @srittau. What does the corresponding Python code do? There should be a code using tracebacklimit in the traceback module.

@srittau
Copy link
Contributor Author

srittau commented Dec 3, 2024

The only instance is this:

limit = getattr(sys, 'tracebacklimit', None)

So, None is supported, but that might be incidental. The following code basically skips over any frame limiting if limit is None, although I'm not sure what that means exactly, as I'm not particular familiar with the traceback module.

@rruuaanng
Copy link
Contributor

The only instance is this:

limit = getattr(sys, 'tracebacklimit', None)

So, None is supported, but that might be incidental. The following code basically skips over any frame limiting if limit is None, although I'm not sure what that means exactly, as I'm not particular familiar with the traceback module.

Can support None, and this is necessary, this's not a incidental. After the getattr(sys, 'tracebacklimit', None) statement is executed, it always returns None, because the tracebacklimit attribute does not exist and it never appears in sys module.

Running Release|x64 interpreter...
Python 3.14.0a0 (heads/master-dirty:ff4e499, Nov 16 2024, 20:59:33) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.tracebacklimit
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    sys.tracebacklimit
AttributeError: module 'sys' has no attribute 'tracebacklimit'

(It's fix appears in another PR of mine.)

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Yeah, I manually checked locally, and setting tracebacklimit to None does the same for the Python implementation (it still might be incidental, but it doesn't matter anyway). Anyways, intentional or not, this seems to be the proper behavior for both implementations of traceback, so this LGTM.

@iritkatriel
Copy link
Member

Thanks, @srittau. What does the corresponding Python code do? There should be a code using tracebacklimit in the traceback module.

@serhiy-storchaka we no longer have C and Python implementations of the traceback formatting logic. It's all in Python now.

@iritkatriel
Copy link
Member

Are there tests for setting it to None?

@serhiy-storchaka
Copy link
Member

There is still C code in _PyTraceBack_Print().

There are tests for setting sys.tracebacklimit to None in test_sys. But the Python implementation in the traceback module is not tested for this.

And it seems to me that setting sys.tracebacklimit to None has different effect on C and Python implementations.

@ZeroIntensity
Copy link
Member

I think it's vice-versa: we're testing the Python implementation, not the C-level _PyTraceBack_Print. Again though, they seem to do the same thing for None, at least if my test was extensive enough.

@hugovk hugovk removed the needs backport to 3.12 only security fixes label Apr 10, 2025
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

6 participants