[Python-Dev] (Specific syntax of) PEP 318 - function/method/class decoration

Gareth McCaughan gmccaughan at synaptics-uk.com
Tue Mar 9 04:42:42 EST 2004


On Monday 2004-03-08 18:48, Phillip J. Eby wrote:

> Anyway, I seem to recall that the bracketed syntax was originally inspired
> by C#'s attribute mechanism, but you'd have to ask the original author to
> be sure.

I think I was the first to propose the bracketed syntax
(in <slrna40k88.2h9o.Gareth.McCaughan at g.local>, after Tim Peters
pointed out a problem with a different syntax I'd proposed for
the same purpose in <slrna3va8t.2a7p.Gareth.McCaughan at g.local>.
The proposal certainly wasn't in the least inspired by C#'s
attribute mechanism; I'd never even seen it then. For what
it's worth, I still have a strong preference for the original
"def f(args) [decorators]:" syntax, despite Guido's preference
for "def f [decorators] (args):".

The problem Tim pointed out was that the first-proposed syntax

    def staticmethod f(args): ...

would confuse over-simple ad hoc parsers (in text editors,
code munging tools, etc.) into thinking that the above was
defining a function or method called "staticmethod".
A similar, but (much?) less severe, problem may attend
the syntax that just moves the decorator-spec to before
the argument list. I suspect this isn't serious enough
to count as a real objection.

-- 
g





More information about the Python-Dev mailing list