Skip to content

Inconsistency between file names of SyntaxErrors and other Exceptions in the new repl #122546

Description

@cfbolz

A small issue, but the new repl reports <unknown> as the file name for SyntaxErrors, but <python-input-x> for other errors:

>>> a b c
  File "<unknown>", line 1
    a b c
      ^
SyntaxError: invalid syntax
>>> 1 / 0
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    1 / 0
    ~~^~~
ZeroDivisionError: division by zero

Classic repl:

>>> a b c
  File "<stdin>", line 1
    a b c
      ^
SyntaxError: invalid syntax
>>> a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    a
NameError: name 'a' is not defined
>>> 

I think this is because _pyrepl.console.InteractiveColoredConsole.showsyntaxerror does not pass on the filename argument to the super method:

    def showsyntaxerror(self, filename=None):
        super().showsyntaxerror(colorize=self.can_colorize)

Should probably wait till #122528 is done. Then, InteractiveColoredConsole could be simplified to overwrite only _showtraceback. The undocumented colorize keyword arguments that showtraceback and showsyntaxerror have gained for pyrepl could be removed again.

Linked PRs

Activity

  1. added
    3.13only security fixes
    3.14bugs and security fixes
    on Aug 1, 2024
  2. added a commit that references this issue on Aug 22, 2024
  3. skirpichev commented on Aug 22, 2024

    @skirpichev
    Member

    pr is ready: #123217

  4. added a commit that references this issue on Aug 22, 2024
  5. added a commit that references this issue on Aug 22, 2024
  6. cfbolz commented on Aug 22, 2024

    @cfbolz
    ContributorAuthor

    there's another form of the bug, with IndentationError, which still shows <unknown>:

    >>>  b
      File "<unknown>", line 1
        b
    IndentationError: unexpected indent
  7. added a commit that references this issue on Aug 22, 2024
  8. skirpichev commented on Aug 22, 2024

    @skirpichev
    Member

    Yes, we should use less strict type check. Correction: #123233.

  9. added 3 commits that reference this issue on Aug 22, 2024
  10. added a commit that references this issue on Aug 23, 2024
  11. pablogsal commented on Aug 23, 2024

    @pablogsal
    Member

    I think we are done. Please reopen if we missed anything. Thanks @skirpichev for the PRs!

  12. added a commit that references this issue on Aug 23, 2024
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

    3.13only security fixes3.14bugs and security fixestopic-replRelated to the interactive shell

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions