New submission from Ned Batchelder <[email protected]>:
Python 3.10 now traces back to with statements when exiting the with block.
When the exit is a break statement, the with exit is visited before the break
statement is. This seems confusing.
--- 8< -----------------------------------------
import linecache, sys
def trace(frame, event, arg):
# The weird globals here is to avoid a NameError on shutdown...
if frame.f_code.co_filename == globals().get("__file__"):
lineno = frame.f_lineno
print("{} {}: {}".format(event[:4], lineno, linecache.getline(__file__,
lineno).rstrip()))
return trace
def doit():
for i in range(2):
with open("test", "w") as f:
a = 13
b = 14
break
c = 16
print(sys.version)
sys.settrace(trace)
doit()
--- 8< -----------------------------------------
3.10.0b2 (default, Jun 3 2021, 05:27:13) [Clang 12.0.0 (clang-1200.0.32.29)]
call 10: def doit():
line 11: for i in range(2):
line 12: with open("test", "w") as f:
line 13: a = 13
line 14: b = 14
line 12: with open("test", "w") as f:
line 15: break
line 16: c = 16
retu 16: c = 16
Shouldn't we get a trace for line 15 (break), then line 12 (with-exit), then
line 15 again, then line 16?
----------
assignee: Mark.Shannon
components: Interpreter Core
messages: 394990
nosy: Mark.Shannon, nedbat
priority: normal
severity: normal
status: open
title: 3.10.0b2 traces with-exit before the break that caused the exit
type: behavior
versions: Python 3.10
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue44298>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com