[Python-3000] callable()

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Fri Jul 28 13:45:13 CEST 2006


Stefan Behnel <behnel_ml at gkec.informatik.tu-darmstadt.de> writes:

> So, if hashable() returns True, it means that a) the designer didn't
> care about switching it off or b) there are cases where it works, so
> it makes sense to try calling it.

If the code can successfully work with either hashable or non-hashable
objects, it can just always try to call it (and deal with potential
failure), rather than test first and then check for failure anyway.

Let me repeat the question: what is hashable() useful for? Please
describe how would you use it, and I will reply with how to do the
same thing simpler, without hashable(), or why it was a bad idea to
begin with.

It's not much better with callable() and iterable(). The only use I
can see is overloading (a parameter plays different roles depending
on its type); the nature of these predicates makes this usage fragile
(adding a seemingly unimportant __call__ definition to a class breaks
code unnecessarily), and the roles should better be specified more
explicitly.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Python-3000 mailing list