Possible PEP: Improve classmethod/staticmethod syntax

Michele Simionato mis6 at pitt.edu
Fri Jun 6 19:20:08 CEST 2003

imbosol at aerojockey.com (Carl Banks) wrote in message news:<60dfb6f6.0306041517.7c34ae85 at posting.google.com>...
> If you do this:
>     def defineproperty(name,bases,clsdict):
>         getter = clsdict.get('get',None)
>         setter = clsdict.get('set',None)
>         deller = clsdict.get('del',None)
>         docstr = clsdict.get('__doc__',None)
>         return property(getter,setter,deller,docstr)
> Then you can make a property metaclass, like this:
>     class foo:
>         "here's the properties doc string"
>         __metaclass__ = defineproperty
>         def get(self):
>             return self.__foo
>         def set(self,value):
>             self.__foo = value
>         def del(self):
>             del self.__foo
> I've never used properties, but if I ever do, this is how I'm doing
> it.  In fact, I would probably do this with static and class
> functions, too.  (I would take the time to make a base class, though,
> so I wouldn't have to set __metaclass__ explicitly.)  

Never post code without testing! ;) This will never work. 

Besides, using a function instead of a metaclass does not work well 
with respect to inheritance and should not be done, except in very special

> I think it should be the STANDARD Python way to define properties and other
> special descriptors.

>From Guido's essay, I got the impression that descriptors are verbose
because they should be called from metaclasses (both his metaclasses 
examples autosuper and autoprop actually do that). Nevertheless, I don't 
think a little syntactic sugar to have a nice notation without recurring 
to metaclasses would be a bad idea.


More information about the Python-list mailing list