"properties" idiom
Terry Hancock
hancock at anansispaceworks.com
Thu Nov 21 15:30:08 EST 2002
Alex, Mike,
Thanks a lot for the replies!
I'm trying out "interfaces" to make well-documented classes:
class MyClassAPI:
"""
Document MyClass API.
"""
def meth1(self):
"""
Document meth1's API
"""
raise NotImplemented("MyClassAPI.meth1")
class MyClass(MyClassAPI):
"""
Actual implementation of MyClass.
"""
def meth1(self):
# do something real
pass
... etc ...
I have the feeling this idea was borrowed from another language (Java?),
where accessor methods are the norm. Creating similar behavior for
properties may be a bit challenging -- especially since this is for Zope,
which often does things to __getattr__, so it's dangerous to mess with it (I
have before, but it can get sticky -- you have to make sure to pass the call
on to the base class's __getattr__ when you're done with it). Zope 2.5.1
also requires Python 2.1, so I can't use the property() method Alex
described, but only the older method (but maybe in a later Zope).
Of course, they can simply be documented in the API's doc string, and/or
be defined with suitable defaults.
So far interfaces seem pretty nice, but I'm not certain whether I'm sold on
them yet or not.
Cheers,
Terry
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
More information about the Python-list
mailing list