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 — The new REPL outputs different tracebeck when custom sys.excepthook is used · Issue #122478 · python/cpython

The new REPL outputs different tracebeck when custom sys.excepthook is used #122478

New issue
Copy link
New issue
Copy link
Closed
Closed
The new REPL outputs different tracebeck when custom sys.excepthook is used#122478
Copy link
Labels
topic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@serhiy-storchaka
serhiy-storchaka
opened on Jul 30, 2024
Issue body actions

Bug report

If sys.systemhook is not sys.__systemhook__, the new REPL outputs the line in the code module in the traceback:

>>> xxx
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    xxx
NameError: name 'xxx' is not defined
>>> import sys; sys.excepthook = lambda *args: sys.__excepthook__(*args)
>>> xxx
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/code.py", line 91, in runcode
    exec(code, self.locals)
    ~~~~^^^^^^^^^^^^^^^^^^^
  File "<python-input-2>", line 1, in <module>
    xxx
NameError: name 'xxx' is not defined

Linked PRs

  • gh-122478: Remove internal frames from tracebacks in REPL #122528
  • [3.12] gh-122478: Remove internal frames from tracebacks in REPL (GH-122528) #122816
  • [3.13] gh-122478: Remove internal frames from tracebacks in REPL (GH-122528) #122817
  • [3.13] gh-122478: Remove internal frames from tracebacks in REPL (GH-122528) #123227

Activity

  1. serhiy-storchaka
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-replRelated to the interactive shellRelated to the interactive shell
    on Jul 30, 2024
  2. serhiy-storchaka commented on Jul 31, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jul 31, 2024
    MemberAuthor
    More actions

    And for compile-time errors:

    >>> ?
      File "<unknown>", line 1
        ?
        ^
    SyntaxError: invalid syntax
    >>> import sys; sys.excepthook = lambda *args: sys.__excepthook__(*args)
    >>> ?
    Traceback (most recent call last):
      File "/home/serhiy/py/cpython/Lib/_pyrepl/console.py", line 172, in runsource
        tree = ast.parse(source)
      File "/home/serhiy/py/cpython/Lib/ast.py", line 53, in parse
        return compile(source, filename, mode, flags,
                       _feature_version=feature_version, optimize=optimize)
      File "<unknown>", line 1
        ?
        ^
    SyntaxError: invalid syntax
  3. devdanzin commented on Jul 31, 2024

    @devdanzin
    devdanzin
    on Jul 31, 2024
    Member
    More actions

    Seems to be done on purpose in code.InteractiveInterpreter.showsyntaxerror:

    cpython/Lib/code.py

    Lines 126 to 132 in bd3d31f

    if sys.excepthook is sys.__excepthook__:
    lines = traceback.format_exception_only(type, value, colorize=colorize)
    self.write(''.join(lines))
    else:
    # If someone has set sys.excepthook, we let that take precedence
    # over self.write
    self._call_excepthook(type, value, tb)

    I suppose this could be overridden in _pyrepl to always output with .write()?

  4. serhiy-storchaka
    added a commit that references this issue on Jul 31, 2024

    pythongh-122478: Remove internal frames from tracebacks in REPL

    8382122
  5. serhiy-storchaka
    changed the title [-]The new REPL outputs different tracebeck when custom sys.systemhook is used[/-] [+]The new REPL outputs different tracebeck when custom sys.excepthook is used[/+] on Jul 31, 2024
  6. serhiy-storchaka
    added a commit that references this issue on Jul 31, 2024

    pythongh-122478: Remove internal frames from tracebacks in REPL

    edfee7f
  7. serhiy-storchaka commented on Jul 31, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jul 31, 2024
    MemberAuthor
    More actions

    sys.excepthook is of course called on purpose, but the traceback was not corrected for it. And sys.last_traceback was not always correct even with the default sys.excepthook.

  8. serhiy-storchaka
    added 2 commits that reference this issue on Aug 7, 2024

    gh-122478: Remove internal frames from tracebacks in REPL (GH-122528)

    e73e7a7

    [3.12] pythongh-122478: Remove internal frames from tracebacks in REPL (

    12ae7b5
  9. miss-islington
    added a commit that references this issue on Aug 8, 2024

    pythongh-122478: Remove internal frames from tracebacks in REPL (pyth…

    7716e72
  10. blhsing
    added a commit that references this issue on Aug 22, 2024

    pythongh-122478: Remove internal frames from tracebacks in REPL (pyth…

    db762d2
  11. cfbolz
    added a commit that references this issue on Aug 22, 2024

    [3.13] pythongh-122478: Remove internal frames from tracebacks in REPL (

    3ae8b72
  12. pablogsal
    added 2 commits that reference this issue on Aug 22, 2024

    [3.13] pythongh-122478: Remove internal frames from tracebacks in REPL (

    37be1c9

    [3.13] gh-122478: Remove internal frames from tracebacks in REPL (GH-…

    30eee22
  13. serhiy-storchaka
    added a commit that references this issue on Aug 23, 2024

    [3.12] gh-122478: Remove internal frames from tracebacks in REPL (GH-…

    8fe586d
  14. skirpichev commented on Jan 21, 2025

    @skirpichev
    skirpichev
    on Jan 21, 2025
    Member
    More actions

    @serhiy-storchaka, can this be closed?

    Reacted by Serhiy Storchaka
  15. serhiy-storchaka
    closed this as completedon Jan 21, 2025
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

    topic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    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.