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

In the new REPL, multiline input execution should fail fast #128231

Open
bswck opened this issue Dec 24, 2024 · 2 comments
Open

In the new REPL, multiline input execution should fail fast #128231

bswck opened this issue Dec 24, 2024 · 2 comments
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@bswck
Copy link
Contributor

bswck commented Dec 24, 2024

Bug report

Bug description:

To reproduce, simply paste this to the new REPL:

raise Exception
print("But I'm powerful enough to bypass it")

Make sure what you are seeing is:

>>> raise Exception
... print("But I'm powerful enough to bypass it")

Once hit enter, the new REPL executes both statements raise Exception and print("But I'm powerful enough to bypass it") from the same, multi-line input block, despite the failure of the first one:

>>> raise Exception
... print("But I'm powerful enough to bypass it")
... 
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    raise Exception
Exception
But I'm powerful enough to bypass it

This can get especially confusing if a statement defines a variable. Like

>>> n = 1 / 0
... print(k-n)

causing

Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    n = 1 / 0
        ~~^~~
ZeroDivisionError: division by zero
Traceback (most recent call last):
  File "<python-input-0>", line 2, in <module>
    print(k-n)
          ^
NameError: name 'k' is not defined

I'd expect different behavior: since those two statements belong to the same input, it is more logical for them to behave like a suite, where the consecutive execution of a statement depends on the completion of the one before it.

CPython versions tested on:

3.13, 3.14

Operating systems tested on:

Linux, macOS, Windows

@bswck bswck added the type-bug An unexpected behavior, bug, or error label Dec 24, 2024
@eendebakpt eendebakpt added the topic-repl Related to the interactive shell label Dec 24, 2024
@bswck
Copy link
Contributor Author

bswck commented Dec 24, 2024

Making a PR for the fix.

@Eclips4
Copy link
Member

Eclips4 commented Dec 24, 2024

Hi! Thanks for the report.
From my perspective as a someone who using REPL everyday, I'm suspect that it would stop executing after first exception.
Let's imagine the next input:

x = foo(arg)  # for some reason, foo raises an exception
y = x * 10  # Would fail with NameError

I'm think that usually lines of code in code blocks are related and depends on each other, so I'm in favor of changing current behavior to "fail on first exception".

@Eclips4 Eclips4 added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Dec 24, 2024
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 type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants