callable() builtin-function

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed Feb 19 20:22:22 EST 2003


On Wed, Feb 19, 2003 at 07:47:19PM -0500, Peter Hansen wrote:
> Andrew Bennetts wrote:
> > 
> > Hence my comment about preferring to have a NotCallableError.  :)
> 
> I'm pretty sure that wouldn't solve the problem.  Think about it --
> the NotCallableError might have been raised by another attempted
> function call *within* the successful call to foo().  You

Of course, but the same applies to all exceptions.

> can't tell the difference unless you explicitly check the top
> level first (though of course that gets you almost nowhere...

You could tell the difference, actually -- check the depth of the
exception's stack.  But I guess this applies to TypeError, too :)

> the call could easily fail for some other reason, so who cares
> if it was really callable if it fails anyway).

You do care about the difference between the top level and a deeper level
raising an error.  The example earlier in this thread trying to determine if
"foo" was a value, or a callable returning a value.  In the case that it is
callable, but raises an exception anyway, it is neither a value or a
callable returning a value, so it is a genuine errror.

-Andrew.






More information about the Python-list mailing list