[Python-Dev] concerns regarding callable() method

Paul Pogonyshev pogonyshev at gmx.net
Sun Apr 8 18:22:57 CEST 2007


Guido van Rossum wrote:
> On 4/8/07, Paul Pogonyshev <pogonyshev at gmx.net> wrote:
> > Guido van Rossum wrote:
> > > 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.)
> 
> My point is that it's futile to use callable() -- even if it passes,
> you have no assurance that you actually have a valid callback. So why
> bother with it at all? It's counter to the spirit of Python. If
> someone passes you a bad callback, they will see a traceback when you
> call it. Then they fix their program. That's how it's supposed to
> work.

I have no problems with Python being untyped.  But I want that error
stack traces provide some useful information as possible with reasonable
effort and that errors happen as early as possible.  In particular, stack
trace should mention that error occured when you passed something wrong
to set_callback() call and not in some obscure place 200 lines later,
because otherwise it will only obfuscate error reason.

Yes, assert will not catch all errors, but at least it will some.  I
consider it perfectly acceptable that you cannot test signature, because
(since Python is untyped) you could only test number of arguments and
even that would probably involve dumb syntax.

So, I understand such assert will not catch all errors.  But I don't
want to remove it, since I find catching at least some errors (e.g. like
passing None) an improvement over catching no errors.

Paul


More information about the Python-Dev mailing list