Joran van Apeldoorn <g...@blubmail.nl> added the comment:
After compiling 3.7 and 3.8 as well it seems that the change happened between those versions. I was a able to patch compiler.c for 3.9 to make it work (first time changing cpython internals, so no guarantees). Patch is attached. This trips up one of the tests in test_trace however, since both the LOAD_NAME before the function def and the CALL_FUNCTION after are counted as a visit to the decorator line. However, this is also the case for your example with the decorators written out, running: def deco1(f): return f def deco2(f): return f def go(): f = 5 f = ( deco1( deco2( f ) ) ) import trace tracer = trace.Trace(count=1,trace=0,countfuncs=0, countcallers=0) tracer.run('go()') for k,v in tracer.results().counts.items(): print(k,v) gives ('<string>', 1) 1 ('/home/user/projects/ShortUse/tracebug/cpython3.9clean/mytracetest.py', 8) 1 ('/home/user/projects/ShortUse/tracebug/cpython3.9clean/mytracetest.py', 10) 2 ('/home/user/projects/ShortUse/tracebug/cpython3.9clean/mytracetest.py', 11) 2 ('/home/user/projects/ShortUse/tracebug/cpython3.9clean/mytracetest.py', 12) 1 ('/home/user/projects/ShortUse/tracebug/cpython3.9clean/mytracetest.py', 5) 1 ('/home/user/projects/ShortUse/tracebug/cpython3.9clean/mytracetest.py', 2) 1 ('/home/user/projects/ShortUse/tracebug/cpython3.9clean/mytracetest.py', 9) 1 while clearly each function is only called ones. In addition, to get back to the 3.6/3.7 problem as well, on 3.6 the slight modification def deco1(f): raise Exception() return f def deco2(f): return f f = 5 f = ( deco1( deco2( f ) ) ) gives Traceback (most recent call last): File "sixtest.py", line 12, in <module> f File "sixtest.py", line 2, in deco1 raise Exception() Exception So the problem is not only with decorators, it is with function calls on multiple lines, in all versions. It seems that: 1. The problem with tracebacks for function calls on multiple lines has been fixed in going from 3.7 to 3.8 (should this fix be merged down as well?) 2. The same problem for decorators has not been fixed (patch attached for 3.9) 3. The fix in 3.8 introduced a bug in the trace module which seems hard to fix. ---------- keywords: +patch Added file: https://bugs.python.org/file48567/decolinenumbers.patch _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37971> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com