Serhiy Storchaka <[email protected]> added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34876>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com