[Python-3000] callable()
Guido van Rossum
guido at python.org
Sat Jul 22 16:58:09 CEST 2006
On 7/22/06, Andrew Koenig <ark-mlist at att.net> wrote:
> This example illustrates an important point: Some object properties don't
> correspond directly to the presence of a particular attribute, and can't
> easily be made to do so.
>
> In other words:
>
> Is it callable? No problem, just check for __call__
>
> Is it iterable? Well, you can't quite check for __iter__ because
> some iterable types don't have them. Well, we can fix that problem:
> Change those types so that they have __iter__ to signal that they
> are iterable.
>
> Is it hashable? That's a tough question to answer, because you
> have to inspect recursively all of the object's components. So
> you can't just test for __hash__; you have to call it.
>
> To my way of thinking, callable, iterable, and hashable are the same kind of
> concept, and I wish Python would provide a uniform way of finding out
> whether such concepts apply to an object. That uniform way doesn't have to
> be in __builtins__, but it would be nice for it to exist.
Hm... Is a uniform API really a good idea for things that have totally
different performance characteristics? Computing hashability is about
as expensive as computing the hash...
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list