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 — gh-102778: IDLE - make sys.last_exc available in Shell after traceback by iritkatriel · Pull Request #103314 · python/cpython

Conversation

@iritkatriel

@iritkatriel iritkatriel commented Apr 6, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fixes #102778.

  • Issue: Add sys.last_exc, deprecate sys.last_type, sys.last_value and sys.last_traceback #102778

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iritkatriel
pythongh-102778: add last_exc in idlelib, to replace sys.last_type/va…
6b74907
…lue/traceback
@iritkatriel
iritkatriel requested a review from terryjreedy as a code owner April 6, 2023 15:52
@bedevere-bot bedevere-bot mentioned this pull request Apr 6, 2023
Add sys.last_exc, deprecate sys.last_type, sys.last_value and sys.last_traceback #102778
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Apr 6, 2023
@iritkatriel

iritkatriel commented Apr 6, 2023

Copy link
Copy Markdown
Member Author

Is this documented anywhere in idlelib docs?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel
add news
ff74713
@terryjreedy

terryjreedy commented Apr 7, 2023

Copy link
Copy Markdown
Member

Yes and no. The 'yes' part is that "Running user code" says that IDLE generally tries to run user code so that it gives the same output (objects) one would get if one runs the same code in python itself, in either batch or interactive mode. Some known differences are then listed in this section and the next, "Displaying output in Shell".

For this issue, user-code sys.last_xyz expressions should have the same result as with python.exe in the same circumstances. In user code, sys.last_exc must continue raising an attribute error in 3.11 like it does in REPL. I considered whether to use last_exc 'internally' in 3.11, but decided to leave 3.11 alone. (And you never suggested touching it.)

In 3.12, last_exc must be set after the the first uncaught-by-user-code 'interactive' exception. Since IDLE intends to simulate running code from an editor with python -i, all user exceptions caught by IDLE are treated as interactive. Hence the two new lines in run.py that unconditionally set last_exc along with the deprecated but still supported attributes. For users, these 2 lines are the only new code relevant to 'Support sys.last_exc in IDLE'. They should have been in the last alpha and should be added, I think, now.

The immediate manual test is that IDLE imitate the REPL as below instead of raising AttributeError as it does now.

>>>import sys; 1/0
Traceback ...
>>> sys.last_exc
ZeroDivisionError('division by zero')

Fixing test_run to check this may or may not be simple.

This change should get a line in What's New 3.12. Check the IDLE entry in What's New 3.11. This could be done later.

The no part is that the rest of the patch, including that to pyshell.py, only concerns stackviewer. This is internal code of no direct concern to users. It need not be done now, or even in 3.12, as it should continue to work. When revised, the support for 2.x string exceptions and the use of the old attributes (which were for support of string exceptions) should be removed. The only effect on users would be that the way to disable stackviewer will change from del sys.last_traceback (undocumented except the the error message ;-) to del sys.last_exc. So revert the current stackview changes and draft a separate PR or wait for me to do so in maybe a week.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@terryjreedy

terryjreedy commented Apr 7, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Reviewing further, I think that the second sys.last_exc = value may not be needed for the user code issue. The test would be to make only the first addition and manually test. The second may be redundant with the first or it may only be used for internal communication. The exception ultimately comes from sys.exc_info (or from a test) and IDLE does not have to use sys as a cache. It should only set sys.last_xyz as needed for non-IDLE code.

In any case, I would like to be able to pass the exception object to stackviewer and its tree item so that the module has no need of sys. Such a change could be attached to #102832 and backported to 3.11. #68978 has a list of possible improvements for stackviewer and if I get familiar with the code again I might want to do some and backport to 3.11.

Closing was an accident. Time to sleep.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@terryjreedy terryjreedy closed this Apr 7, 2023
@terryjreedy terryjreedy reopened this Apr 7, 2023
@terryjreedy
Merge branch 'main' into exc_info-idlelib
c58c51b
@terryjreedy

terryjreedy commented Apr 7, 2023

Copy link
Copy Markdown
Member

I verified that the setting of sys.last_exc in print_exception should be sufficient.

iritkatriel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel added 2 commits April 7, 2023 23:09
@iritkatriel
revert most changes
6e6f60b
@iritkatriel
remove one more
d407a35
@iritkatriel iritkatriel changed the title gh-102778: add last_exc in idlelib, to replace sys.last_type/value/traceback gh-102778: add last_exc in idlelib, to eventually replace sys.last_type/value/traceback Apr 7, 2023
@terryjreedy terryjreedy changed the title gh-102778: add last_exc in idlelib, to eventually replace sys.last_type/value/traceback gh-102778: IDLE - make sys.last_exc available in Shell after traceback Apr 19, 2023
@terryjreedy
terryjreedy merged commit d1e4917 into python:main Apr 19, 2023
@bedevere-bot bedevere-bot removed the awaiting core review label Apr 19, 2023
@terryjreedy terryjreedy mentioned this pull request Apr 19, 2023
gh-102832: IDLE - remove use of deprecated sys.last_xyzs for stackviewer #103339
Merged
carljm added a commit to carljm/cpython that referenced this pull request Apr 20, 2023
@carljm
Merge branch 'main' into superopt
5c0a21c
* main: (24 commits)
  pythongh-98040: Move the Single-Phase Init Tests Out of test_imp (pythongh-102561)
  pythongh-83861: Fix datetime.astimezone() method (pythonGH-101545)
  pythongh-102856: Clean some of the PEP 701 tokenizer implementation (python#103634)
  pythongh-102856: Skip test_mismatched_parens in WASI builds (python#103633)
  pythongh-102856: Initial implementation of PEP 701 (python#102855)
  pythongh-103583: Add ref. dependency between multibytecodec modules (python#103589)
  pythongh-83004: Harden msvcrt further (python#103420)
  pythonGH-88342: clarify that `asyncio.as_completed` accepts generators yielding tasks (python#103626)
  pythongh-102778: IDLE - make sys.last_exc available in Shell after traceback (python#103314)
  pythongh-103582: Remove last references to `argparse.REMAINDER` from docs (python#103586)
  pythongh-103583: Always pass multibyte codec structs as const (python#103588)
  pythongh-103617: Fix compiler warning in _iomodule.c (python#103618)
  pythongh-103596: [Enum] do not shadow mixed-in methods/attributes (pythonGH-103600)
  pythonGH-100530: Change the error message for non-class class patterns (pythonGH-103576)
  pythongh-95299: Remove lingering setuptools reference in installer scripts (pythonGH-103613)
  [Doc] Fix a typo in optparse.rst (python#103504)
  pythongh-101100: Fix broken reference `__format__` in `string.rst` (python#103531)
  pythongh-95299: Stop installing setuptools as a part of ensurepip and venv (python#101039)
  pythonGH-103484: Docs: add linkcheck allowed redirects entries for most cases (python#103569)
  pythongh-67230: update whatsnew note for csv changes (python#103598)
  ...
@iritkatriel
iritkatriel deleted the exc_info-idlelib branch July 25, 2023 18:05
@scauligi scauligi mentioned this pull request Nov 17, 2025
sys.last_exc not set upon exception hylang/hy#2674
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@terryjreedy terryjreedy Awaiting requested review from terryjreedy terryjreedy is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add sys.last_exc, deprecate sys.last_type, sys.last_value and sys.last_traceback

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@iritkatriel @terryjreedy @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.