Hey Fred. It might not be a good idea to nest the "property class" like an inner class. It may be plausible that property objects are reusable between classes. As implied by this syntax, it wouldn't be reuseable. Another point, is that they may be very large. Which would be messy. I did i bit of brainstorming. One purpose of the type objects is a means to coerce one object to another. So here is the pattern. Just like str(MyObject) requires __str__, or len(MyObject) requires __len__ or any of the factory functions for that matter, the property factory function would require that your object support both __get__ , __set__ , and __del__. Thats it. So instead of, property(fset,fget,fdel)you would instead have, property(AnyObjectSupportingAboveInterface). How the property factory function differs from the others is that it will only check for the existence of these methods, and will not execute the code within them. It instead sets a flag on the object indicating that it is active. Will be necessary to do checking on every object for every set, or every get. Not too bad though. How time consuming is two if statements? Is this making sense? John Coppola --- "Fred L. Drake, Jr." <fdrake@acm.org> wrote: > > Fred L. Drake, Jr. writes: > [describing a suggested property syntax] > > class Foo(object): > > property myprop: > > """A computed property on Foo objects.""" > > > > def __get__(self): > > return ... > > Perhaps it was obvious to everyone else, but it just > occured to me > that this lends itself to inheriting descriptor > types: > > > class ReadOnly(object): > def __get__(self): > raise NotImplementedError("sub-class must > override this!") > > def __set__(self): > raise AttributeError("read-only attribute") > > def __delete__(self): > raise AttributeError("read-only attribute") > > > class Foo(object): > property myprop(ReadOnly): > def __get__(self): > return ... > > > > -Fred > > -- > Fred L. Drake, Jr. <fdrake at acm.org> > PythonLabs at Zope Corporation > > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/mailman/listinfo/python-dev __________________________________________________ Do You Yahoo!? Yahoo! Sports - Coverage of the 2002 Olympic Games http://sports.yahoo.com
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