Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16015 > unrolled thread
| Started by | Andrea Crotti <andrea.crotti.0@gmail.com> |
|---|---|
| First post | 2011-11-21 15:35 +0000 |
| Last post | 2011-11-21 15:35 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: decorators and closures Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-21 15:35 +0000
| From | Andrea Crotti <andrea.crotti.0@gmail.com> |
|---|---|
| Date | 2011-11-21 15:35 +0000 |
| Subject | Re: decorators and closures |
| Message-ID | <mailman.2905.1321889718.27778.python-list@python.org> |
On 11/21/2011 03:06 PM, Dave Angel wrote:
> Your function 'nested' isn't nested, 'fun' is. What you discovered is
> that a decorator is always executed, every time a nested decorated
> function is defined.
>
> You've also ust proved that it would be an incompatible change.
> Doesn't that answer the question? An optimizer that changes the
> behavior isn't usually desirable.
>
Yes sure I think it makes perfectly sense, because you actually redefine
a local variable every time..
Another thing (which was also the reason of the subject), I tried to
disassemble the following:
def dec(fn):
def _dec():
fn()
return _dec
@dec
def fun():
print("here")
fun()
And I get this:
In [29]: dis.dis(test_decorate)
Disassembly of dec:
2 0 LOAD_CLOSURE 0 (fn)
3 BUILD_TUPLE 1
6 LOAD_CONST 1 (<code object _dec at
0x1c4b930, file "test_decorate.py", line 2>)
9 MAKE_CLOSURE 0
12 STORE_FAST 1 (_dec)
5 15 LOAD_FAST 1 (_dec)
18 RETURN_VALUE
Disassembly of fun:
3 0 LOAD_DEREF 0 (fn)
3 CALL_FUNCTION 0
6 POP_TOP
7 LOAD_CONST 0 (None)
10 RETURN_VALUE
Looking up the definition of the single calls didn't help much, so why
do we need
for example MAKE_CLOSURE?
Is MAKE_CLOSURE just more generic maybe?
Back to top | Article view | comp.lang.python
csiph-web