When a return statement also executes a finally clause, the sequence of lines reported to the trace function is different in 3.8 than it has been before 3.8:
$ cat finally_trace.py
def return_from_finally():
try:
print("returning")
return 17
finally:
print("finally")
def trace(frame, event, arg):
print(frame.f_lineno, event)
return trace
import sys
sys.settrace(trace)
return_from_finally()
$ python3.7 finally_trace.py
1 call
2 line
3 line
returning
4 line
6 line
finally
6 return
$ python3.8 finally_trace.py
1 call
2 line
3 line
returning
4 line
6 line
finally
4 line
4 return
Is this intentional? Is it a bug? Will it change back before 3.8 is shipped?