Author serhiy.storchaka
Recipients ammar2, nedbat, serhiy.storchaka
Date 2018-10-03.10:56:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538564168.84.0.545547206417.issue34876@psf.upfronthosting.co.za>
In-reply-to
Content
First the decorator itself is loaded. Then the function is created, decorators are called and the result is bound to the name.

There is similar situation in the case of multiline call.

$ cat -n multiline_call.py 
     1  def f(a, b):
     2      return [
     3          a,
     4          b,
     5      ]
     6
     7  x = f(
     8      1,
     9      2,
    10  )

$ ./python -m trace --trace multiline_call.py

In 3.7:

 --- modulename: multiline_call, funcname: <module>
multiline_call.py(1): def f(a, b):
multiline_call.py(7): x = f(
multiline_call.py(8):     1,
multiline_call.py(9):     2,
 --- modulename: multiline_call, funcname: f
multiline_call.py(3):         a,
multiline_call.py(4):         b,

In 3.8:

 --- modulename: multiline_call, funcname: <module>
multiline_call.py(1): def f(a, b):
multiline_call.py(7): x = f(
multiline_call.py(8):     1,
multiline_call.py(9):     2,
multiline_call.py(7): x = f(
 --- modulename: multiline_call, funcname: f
multiline_call.py(3):         a,
multiline_call.py(4):         b,
multiline_call.py(2):     return [

Line 7 started the execution with loading the function f. Then arguments are evaluated on lines 1 and 2. Then line 7 continue the execution with calling the function and consuming its result.

Maybe using a range of lines instead of a single line will help (as was discussed in issue12458). First time the single line with a decorator is executed, second time the multiline expression that starts with the same line is executed. But this may require a significant change of AST and bytecode format.
History
Date User Action Args
2018-10-03 10:56:08serhiy.storchakasetrecipients: + serhiy.storchaka, nedbat, ammar2
2018-10-03 10:56:08serhiy.storchakasetmessageid: <1538564168.84.0.545547206417.issue34876@psf.upfronthosting.co.za>
2018-10-03 10:56:08serhiy.storchakalinkissue34876 messages
2018-10-03 10:56:08serhiy.storchakacreate