Skip to content
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

gh-82378 fix sys.tracebacklimit in pyrepl #123062

Conversation

cfbolz
Copy link
Contributor

@cfbolz cfbolz commented Aug 16, 2024

This is a slightly more invasive approach to #82378 than the one in #122452. In addition to the changes there, the PR also changes the way that _pyrepl.console.InteractiveColoredConsole interacts with code.InteractiveConsole. The PR removes new keyword arguments colorize (and limit) of the methods code.InteractiveConsole.showsyntaxerror and .showtraceback. The keyword arguments were added only for pyrepl, and not documented and only indirectly tested. Instead of using these keyword arguments, pyrepl now overwrites the new _showtraceback helper method.

The new undocumented keyword arguments broke some third-party libraries on PyPy pypy/pypy#5004 (comment), however in ways that are extremely unlikely to affect CPython.

I cannot decide whether this is a too radical change this late in the release process. @serhiy-storchaka what do you think?

cfbolz added 5 commits July 30, 2024 14:01
make sure that pyrepl uses the same logic for sys.tracebacklimit as both
the basic repl and the standard sys.excepthook
remove the undocumented new keyword arguments colorize and limit that
were added only for pyrepl
cfbolz added a commit to pypy/pypy that referenced this pull request Aug 16, 2024
this removes the extra keyword argument colorize in showtraceback and
showsyntaxerror again, which should hopefully fix the problems in
gh-5004.
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

I feel discomfort both from the current code and from this PR.

The current code violates the Liskov substitution principle: the signatures of showsyntaxerror() and showtraceback() in subclasses are not compatible with signatures in the base class.

In this PR the overridden _showtraceback() has compatible signature, but ignores its arguments. And what if we will need to pass additional arguments to format_exception() in a subclass? We will need to modify the base class.

Lib/test/test_pyrepl/test_pyrepl.py Outdated Show resolved Hide resolved
Lib/test/test_pyrepl/test_pyrepl.py Outdated Show resolved Hide resolved
Lib/code.py Show resolved Hide resolved
Lib/code.py Outdated Show resolved Hide resolved
@cfbolz
Copy link
Contributor Author

cfbolz commented Aug 16, 2024

@serhiy-storchaka thanks for your super thoughtful comments. I share your sense of discomfort, there's definitely too tight coupling between InteractiveConsole and pyrepl. I'll try to implement something along the lines of your suggestion. Since you aren't objecting to the removal of the undocumented arguments, I'll close #122452 ;-).

@cfbolz
Copy link
Contributor Author

cfbolz commented Aug 16, 2024

@serhiy-storchaka I did your suggestions, let me know what you think.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM.

Lib/test/test_pyrepl/test_pyrepl.py Outdated Show resolved Hide resolved
Lib/test/test_pyrepl/test_pyrepl.py Outdated Show resolved Hide resolved
@cfbolz
Copy link
Contributor Author

cfbolz commented Aug 16, 2024

@serhiy-storchaka thanks for all your help!

@pablogsal pablogsal merged commit 63603bc into python:main Aug 18, 2024
42 checks passed
@pablogsal pablogsal added the needs backport to 3.13 bugs and security fixes label Aug 18, 2024
@miss-islington-app
Copy link

Thanks @cfbolz for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app
Copy link

Sorry, @cfbolz and @pablogsal, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 63603bca35798c166e1b8e0be76aef69217f8b1b 3.13

cfbolz added a commit to cfbolz/cpython that referenced this pull request Aug 18, 2024
…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>
jeremyhylton pushed a commit to jeremyhylton/cpython that referenced this pull request Aug 19, 2024
…23062)

Make sure that pyrepl uses the same logic for sys.tracebacklimit as both
the basic repl and the standard sys.excepthook
blhsing pushed a commit to blhsing/cpython that referenced this pull request Aug 22, 2024
…23062)

Make sure that pyrepl uses the same logic for sys.tracebacklimit as both
the basic repl and the standard sys.excepthook
cfbolz added a commit to cfbolz/cpython that referenced this pull request Aug 22, 2024
…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>
cfbolz added a commit to cfbolz/cpython that referenced this pull request Aug 23, 2024
…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>
@bedevere-app
Copy link

bedevere-app bot commented Aug 23, 2024

GH-123252 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Aug 23, 2024
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.12 bug and security fixes label Aug 23, 2024
@miss-islington-app
Copy link

Thanks @cfbolz for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @cfbolz and @pablogsal, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 63603bca35798c166e1b8e0be76aef69217f8b1b 3.12

pablogsal pushed a commit that referenced this pull request Aug 23, 2024
…) (#123252)

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)
@bedevere-app
Copy link

bedevere-app bot commented Aug 23, 2024

GH-123252 is a backport of this pull request to the 3.13 branch.

@pablogsal pablogsal changed the title gh-82378 fix sys.tracebacklimit in pyrepl, approach 2 gh-82378 fix sys.tracebacklimit in pyrepl Aug 23, 2024
@cfbolz
Copy link
Contributor Author

cfbolz commented Aug 24, 2024

it doesn't really make sense to backport this to 3.12, because it's about pyrepl, does it? it still has the "needs backport" label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs backport to 3.12 bug and security fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants