[Python-3000] callable()

Steven Bethard steven.bethard at gmail.com
Fri Jul 28 03:53:29 CEST 2006


On 7/27/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
> > So how about we change callable() and add hashable(), iterable() and
> > whatever else makes sense so that these all become like this:
> >
> >   def callable(x):
> >     return getattr(x, "__call__", None) is not None
>
> This *still* doesn't fully solve the problem in the case
> of __hash__, since a container may be unhashable due to
> its contents, even if it has a __hash__ method itself.

For that matter, it doesn't solve the problem for __call__ or __iter__
either since they could also raise TypeErrors.  Any of these
method-checking approaches can only tell you if an object *doesn't*
support operation X. Their return values should really be read as:

    False -- definitely doesn't support operation X
    True -- could possibly support operation X

Maybe we should reverse the polarity and rename them to
isdefinitelynotcallable(), isdefinitelynotiterable(), etc.? ;-)

STeVe
-- 
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
        --- Bucky Katt, Get Fuzzy


More information about the Python-3000 mailing list