Callable assertion?

Terry Reedy tjreedy at udel.edu
Sun Oct 5 17:08:36 EDT 2003


"Roy Smith" <roy at panix.com> wrote in message
news:roy-2F0C3F.13005105102003 at reader2.panix.com...
> In article <h5GcnUOo2b742R2iXTWJhQ at comcast.com>,
>  "Terry Reedy" <tjreedy at udel.edu> wrote:
> > The acid test is to try calling it:
> >
> > try: param()
> > except TypeError, msg: <do whatever>
>
> The problem there is that it really calls the function!

Of course.  You only do this test when you actually want the function
called.

> I want to test
> the paramater for correctness in my constructor,

I was afraid of that ;-).

> but I don't actually
> want it called until it's supposed to be called.  Calling the
function
> to prove it's callable is kind of like checking to see if a gun's
safety
> is on by pulling the trigger :-)

But it is the Python way.  Someone recently asked how to test if one
can connect to a site without actually connecting and Alex M. gave
much the same answer I did.  The frequent question "how can I tell if
I can read a file without actually reading it" gets the stock answer
'you can't, not for sure', just as iscallable is 'not for sure'.
Sorry, time-varying reality and the possibility of lies sometimes
bites

> Not to mention that param might indeed be callable and the TypeError
is
> being generated (and not caught) somewhere further down.

That is why I suggested looking at the message, although you are
right, the same message could also be passed up.

Terry J. Reedy






More information about the Python-list mailing list