This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 <>
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 
     1  def f(a, b):
     2      return [
     3          a,
     4          b,
     5      ]
     7  x = f(
     8      1,
     9      2,
    10  )

$ ./python -m trace --trace

In 3.7:

 --- modulename: multiline_call, funcname: <module> def f(a, b): x = f(     1,     2,
 --- modulename: multiline_call, funcname: f         a,         b,

In 3.8:

 --- modulename: multiline_call, funcname: <module> def f(a, b): x = f(     1,     2, x = f(
 --- modulename: multiline_call, funcname: f         a,         b,     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.
Date User Action Args
2018-10-03 10:56:08serhiy.storchakasetrecipients: + serhiy.storchaka, nedbat, ammar2
2018-10-03 10:56:08serhiy.storchakasetmessageid: <>
2018-10-03 10:56:08serhiy.storchakalinkissue34876 messages
2018-10-03 10:56:08serhiy.storchakacreate