[Zope3-dev] interface conventions: default=_RAISE_ERROR
Barry A. Warsaw
barry@zope.com
Wed, 15 May 2002 12:18:13 -0400
>>>>> "GvR" == Guido van Rossum <guido@python.org> writes:
>> So if you had to do it over again, what would the
>> signature/semantics of getattr() be?
GvR> Not sure, but perhaps getattrdefault(obj, name, default) for
GvR> the 3-arg version and getattr(obj, name) for the 2-arg
GvR> version that raises an exception when obj.<name> doesn't
GvR> exist.
GvR> BTW, I take it back that 50% of the getattr() calls in the
GvR> stdlib don't catch the exception. It's probably closer to
GvR> 90% -- the 3-arg variant is truly rare, and the 2-arg variant
GvR> inside try/except is pretty rare.
I think that matches my own experiences. I tend to use getattr()
itself in introspective situations, where I'm trying to sniff at an
object to see if it supports a particular interface (method) or not.
In the face of formal Interfaces, its use altogether may diminish (in
library code, if not in the Python core).
-Barry