-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
3.11 regression: tracing with-statement on exit from block #89872
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
Comments
Python 3.11 seems to have reverted a behavior that was new in 3.10.0b1: exiting a with-statement re-visits the with line on the way out. --- %< bug2.py ---------------------- 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
print(sys.version)
sys.settrace(trace)
import contextlib
def f():
with contextlib.nullcontext():
1/0
f() Running with 3.10 shows re-visiting the with: $ python3.10 bug2.py
3.10.0 (default, Oct 4 2021, 17:22:29) [Clang 12.0.0 (clang-1200.0.32.29)]
call 15: def f():
line 16: with contextlib.nullcontext():
line 17: 1/0
exce 17: 1/0
line 16: with contextlib.nullcontext():
retu 17: 1/0
Traceback (most recent call last):
File "/System/Volumes/Data/root/src/foo/bug1270/bug2.py", line 19, in <module>
f()
File "/System/Volumes/Data/root/src/foo/bug1270/bug2.py", line 17, in f
1/0
ZeroDivisionError: division by zero 3.11 does not: $ python3.11 bug2.py
3.11.0a1 (default, Oct 6 2021, 07:21:05) [Clang 12.0.0 (clang-1200.0.32.29)]
call 15: def f():
line 16: with contextlib.nullcontext():
line 17: 1/0
exce 17: 1/0
retu 17: 1/0
Traceback (most recent call last):
File "/System/Volumes/Data/root/src/foo/bug1270/bug2.py", line 19, in <module>
f()
^^^
File "/System/Volumes/Data/root/src/foo/bug1270/bug2.py", line 17, in f
1/0
~^~
ZeroDivisionError: division by zero Versions before 3.10 also do not visit the with statement: $ python3.9 bug2.py
3.9.7 (default, Sep 7 2021, 22:16:49)
[Clang 12.0.0 (clang-1200.0.32.29)]
call 15: def f():
line 16: with contextlib.nullcontext():
line 17: 1/0
exce 17: 1/0
line 17: 1/0
retu 17: 1/0
Traceback (most recent call last):
File "/System/Volumes/Data/root/src/foo/bug1270/bug2.py", line 19, in <module>
f()
File "/System/Volumes/Data/root/src/foo/bug1270/bug2.py", line 17, in f
1/0
ZeroDivisionError: division by zero Is this a bug in 3.11, or an intentional return to previous behavior? (BTW: there is no 3.11regression keyword available) |
BTW, this is the coverage.py issue: nedbat/coveragepy#1270 |
Probably an oversight when converting to zero-overhead exceptions. |
Sorry about the delay in fixing this. |
Mark, os something left to do here? |
I can confirm that this fixes the problem. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: