Closed
Description
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 a successful completion of the one before it.
CPython versions tested on:
3.13, 3.14
Operating systems tested on:
Linux, macOS, Windows
Linked PRs
- gh-128231: Use
runcode()
return value for failing early #129488 - [3.13] gh-128231: Use
runcode()
return value for failing early (GH-129488) #130513 - [3.13] Revert "gh-128231: Use
runcode()
return value for failing early (GH-129488) (#130513)" #131834 - gh-128231: Use
runcode()
return value for failing early (fix test) #131835