A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-August/047583.html below:

[Python-Dev] Decorator order implemented backwards?

[Python-Dev] Decorator order implemented backwards? [Python-Dev] Decorator order implemented backwards?Guido van Rossum guido at python.org
Wed Aug 11 02:09:54 CEST 2004
> No, it has always been this way round.  In fact test_order was inherited
> from Guido's original version of test_decorators.py (from patch #926860)
> where it read:
> 
>     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)
> 
> (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/)
More information about the Python-Dev mailing list

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