[Python-Dev] concerns regarding callable() method

Guido van Rossum guido at python.org
Sun Apr 8 17:39:30 CEST 2007


On 4/8/07, Paul Pogonyshev <pogonyshev at gmx.net> wrote:
> I have seen in PEP 3100 that callable() function is planned to be
> removed in Python 3000 with this replacement: "just call the object
> and catch the exception???".  For one, the object (if it is
> callable) can raise exception itself, so you need to somehow to
> differentiate between exception raised inside its __call__ and
> exception raised if object is not callable to begin with.

Why?

> Additionally consider something like
>
>         something.set_callback (x)
>
> Assume that set_callback() wants to check if `x' is callable at
> all, to raise exception early and make error tracking easier.
> Currently, you can
>
>         assert callable (x)
>
> But if callable() is removed, there is no apparent replacement.  Of
> course, you cannot call `x' since it might have side-effects or be
> slow etc.

assert hasattr(x, '__call__')

I note that callable() was introduced before all callable objects had
a __call__ attribute. This is no longer the case, so it's not needed.

> Please reconsider removal of callable() or provide an adequate
> replacement.

What if someone passes a callable that doesn't have the expected signature?

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list