[Python-3000] callable()

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Jul 19 03:12:36 CEST 2006


Guido van Rossum wrote:

> But I'm not proposing to use hasattr(obj, '__call__'). I'm basically
> saying that the callable test has very little to do with whether the
> later call will succeed, because we have no way to test the signature.

I don't think that's needed for the sort of things people
want callable() for. I think they want it for the purpose
of implementing type-dependent APIs -- similar in spirit
to doing different things depending on whether you're
passed a sequence or not, etc.

For that purpose, hasattr(obj, '__call__') is sufficient,
I think. And if it's not, the API you're trying to
implement is ill-conceived in the first place, just like
testing for sequenceness is not a well-defined operation.

--
Greg


More information about the Python-3000 mailing list