[Python-Dev] Decorator order implemented backwards? (original) (raw)
Guido van Rossum guido at python.org
Wed Aug 11 02:09:54 CEST 2004
- Previous message: [Python-Dev] Drop support for multiple decorators per line? (was: Decorator order implemented backwards?)
- Next message: [Python-Dev] Decorator order implemented backwards?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
No, it has always been this way round. In fact testorder was inherited from Guido's original version of testdecorators.py (from patch #926860) where it read:
def testorder(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) (i.e. identical to the current version except for the change in syntax). In fact I relied on the fact that this test passed to convince me I had the order right! But I should have spotted the inconsistency between that and the documentation that I wrote for the reference manual.
Oops. When using a list, it makes sense to apply the decorators left-to-right. But when using @deco, I think it makes more sense that the decorators closer to the def are applied first. IOW the syntax is conceptually right-recursive:
definition ::= '@' decorator definition | 'def' ...
I'll do a patch to fix the order and the corresponding tests.
Great.
While I'm at it, do we want to drop support for multiple decorators on a single line? Nobody has spoken up for it, and in fact forcing one-per-line would simplify the grammar (as well as making it easier for toy parsers to find decorators).
+1
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Drop support for multiple decorators per line? (was: Decorator order implemented backwards?)
- Next message: [Python-Dev] Decorator order implemented backwards?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]