Revised PEP 318 - Function/Method Decorator Syntax
Duncan Booth
duncan at NOSPAMrcp.co.uk
Wed Jun 11 08:48:24 EDT 2003
Bernhard Herzog <bh at intevation.de> wrote in
news:6qwufsn9un.fsf at salmakis.intevation.de:
> But then again with decorators I might just as well write
>
> def foo(self) as attributed(my_attr = "bar"):
> pass
>
> with attributed defined as e.g.
>
> def attributed(**kw):
> def add_attrs(f):
> for key, value in kw.items():
> setattr(f, key, value)
> return add_attrs
>
I doubt this would have the desired effect. Perhaps we should take this as
a warning: the proposed syntax seems to lead to people writing code
snippets like the one above which would result in foo==None.
I think the problem may be that the assignment to foo is sufficiently
obfuscated that it is too easy to forget its happening, or perhaps it's
just that forcing the decorators to work by returning an intermediate
function is an extra level of indirection that it would be nice to do
without.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list