I haven't seen anyone remark upon this yet, but the order of decorator application appears to be implemented backwards. According to the PEP: > Proposed Syntax > > The current syntax for function decorators as implemented in Python > 2.4a2 is: > @dec2 > @dec1 > def func(arg1, arg2, ...): > pass > > > This is equivalent to: > def func(arg1, arg2, ...): > pass > func = dec2(dec1(func)) However, it seems the '@' form is really doing dec1(dec2(func)), not dec2(dec1(func)). The test_decorators.py reveals that it is, indeed, testing *for* the wrong behavior. test_decorators.py: > def test_order(self): > class C(object): > @funcattrs(abc=1) @staticmethod > def foo(): return 42 > # This wouldn't work if staticmethod was called first > self.assertEqual(C.foo(), 42) > self.assertEqual(C().foo(), 42) So, um...I assume this is a bug in the implementation, not the PEP, because the PEP's way makes sense and the way it's implemented doesn't. James
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4