[Python-3000] Builtin iterator type

George Sakkis george.sakkis at gmail.com
Sat Nov 18 17:18:15 CET 2006


On 11/17/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Bill Janssen wrote:
> > Checking for some textual attributes of a
> > type
>
> Now you're talking about LYBL, which is generally
> considered an anti-pattern in Python. APIs should
> be designed so that you don't need to test for the
> presence of features.

The end user may not have to explicitly test for it, but it happens
anyway behind the scenes; x.foo is functionally equivalent to
if hasattr(x,'foo'): return getattr(x,'foo')
else: raise AttributeError()

I think Bill's point is not whether you have to be explicit about it
or the language does it for you, but that the textual check must
happen at some point, and that this is inherently unsafer than a
semantic check.

George


More information about the Python-3000 mailing list