[Python-Dev] concerns regarding callable() method (original) (raw)

Paul Pogonyshev pogonyshev at gmx.net
Sun Apr 8 17:56:42 CEST 2007


Guido van Rossum wrote:

On 4/8/07, Paul Pogonyshev <pogonyshev at gmx.net> wrote: > Additionally consider something like > > something.setcallback (x) > > Assume that setcallback() 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.

I just didn't think about that possibility. If that works the same way, callable() is just a sugar and not something unimplementable in other ways. Therefore, my objection is discarded. (But PEP 3100 should probably be update to mention this, otherwise you may get this complaint again ;)

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

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

Well, I don't know a way to catch such situations now, so removing callable() will not make it worse (even if you don't know about hasattr trick above.)

Paul



More information about the Python-Dev mailing list