Author control-k
Recipients control-k, nedbat, serhiy.storchaka
Date 2019-08-29.14:36:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1567089387.98.0.379395277596.issue37971@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-08-29 14:36:28control-ksetrecipients: + control-k, nedbat, serhiy.storchaka
2019-08-29 14:36:27control-ksetmessageid: <1567089387.98.0.379395277596.issue37971@roundup.psfhosted.org>
2019-08-29 14:36:27control-klinkissue37971 messages
2019-08-29 14:36:27control-kcreate