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

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

Closed
cfbolz opened this issue Aug 1, 2024 · 4 comments
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell

Comments

@cfbolz
Copy link
Contributor

cfbolz commented Aug 1, 2024

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

@Eclips4 Eclips4 added the topic-repl Related to the interactive shell label Aug 1, 2024
@AlexWaygood AlexWaygood added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Aug 1, 2024
@skirpichev
Copy link
Member

pr is ready: #123217

pablogsal pushed a commit that referenced this issue Aug 22, 2024
…23217)

* gh-122546: use same filename for different exceptions in new repl

* +1
skirpichev added a commit to skirpichev/cpython that referenced this issue Aug 22, 2024
… new repl (pythonGH-123217)

* pythongh-122546: use same filename for different exceptions in new repl

* +1
(cherry picked from commit 3d7b1a5)

Co-authored-by: Sergey B Kirpichev <[email protected]>
@cfbolz
Copy link
Contributor Author

cfbolz commented Aug 22, 2024

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

>>>  b
  File "<unknown>", line 1
    b
IndentationError: unexpected indent

@skirpichev
Copy link
Member

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

@pablogsal
Copy link
Member

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

pablogsal pushed a commit that referenced this issue Aug 23, 2024
…new REPL (GH-123233) (#123247)

gh-122546: Relax SyntaxError check when raising errors on the new REPL (GH-123233)
(cherry picked from commit 4c3f0cb)

Co-authored-by: Sergey B Kirpichev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell
Projects
None yet
Development

No branches or pull requests

5 participants