Revised PEP 318 - Function/Method Decorator Syntax

Ian Bicking ianb at colorstudy.com
Wed Jun 11 22:16:55 CEST 2003


On Wed, 2003-06-11 at 07:48, Duncan Booth wrote:
> > 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.

Accidental Nones happens a lot in Python, I don't think we should try to
avoid it.  But, it might be nice to say that the decorator is not
allowed to return None, so there would be an exception in this case...
then at least these bugs will be quickly caught.

  Ian







More information about the Python-list mailing list