[Zope3-dev] interface conventions: default=_RAISE_ERROR
Barry A. Warsaw
barry@zope.com
Wed, 15 May 2002 10:19:13 -0400
>>>>> "GvR" == Guido van Rossum <guido@python.org> writes:
GvR> I think you're going too far here. While it's sometimes
GvR> inconvenient that getattr() raises an exception (I think that
GvR> maybe 50% of the occurrences in the standard library are
GvR> surrounded by a try/except), the customary default of None
GvR> really doesn't work for getattr(), because it's a legal
GvR> value. dict.get() is different because it is specifically
GvR> intended to provide a default, and the dict[key] notation is
GvR> available for when the exception is okay.
Good point.
GvR> What's wrong with getattr() is that it raises an exception
GvR> with 2 arguments but returns a default with 3 arguments, and
GvR> that's the pattern we're trying to stomp out here -- not the
GvR> idea that accessors can raise exceptions.
So if you had to do it over again, what would the signature/semantics
of getattr() be?
-Barry