Bug report
Checklist
- I am confident this is a bug in CPython, not a bug in a third-party project
- I have searched the CPython issue tracker,
and am confident this bug has not been reported before
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux, Windows
Output from running 'python -VV' on the command line:
No response
A clear and concise description of the bug:
Consider the following codeblock that works correctly when interrupted by ctrl+c.
try:
while 1:
pass
except KeyboardInterrupt:
print("Exception handling works!")
Exception handling works!
Now we push the pass into the same line and suddenly our try-except is ignored entirely:
try:
while 1: pass
except KeyboardInterrupt:
print("Exception handling works!")
Traceback (most recent call last):
File "/home/panta/issue.py", line 2, in <module>
while 1: pass
KeyboardInterrupt
This was quite a surprise to me because I naively expected both approaches to emit the same bytecode (except with different line info).
Reactions are currently unavailable
Bug report
Checklist
and am confident this bug has not been reported before
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux, Windows
Output from running 'python -VV' on the command line:
No response
A clear and concise description of the bug:
Consider the following codeblock that works correctly when interrupted by ctrl+c.
Now we push the pass into the same line and suddenly our try-except is ignored entirely:
Traceback (most recent call last): File "/home/panta/issue.py", line 2, in <module> while 1: pass KeyboardInterruptThis was quite a surprise to me because I naively expected both approaches to emit the same bytecode (except with different line info).