Callable assertion?
Roy Smith
roy at panix.com
Sun Oct 5 13:00:51 EDT 2003
In article <h5GcnUOo2b742R2iXTWJhQ at comcast.com>,
"Terry Reedy" <tjreedy at udel.edu> wrote:
> "Roy Smith" <roy at panix.com> wrote in message
> news:roy-F9A420.08554505102003 at reader2.panix.com...
> > I've got a function which gets passed a call-back function as a
> > parameter. I want to check to make sure the thing passed in is
> indeed
> > callable.
>
> 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! I want to test
the paramater for correctness in my constructor, 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 :-)
Not to mention that param might indeed be callable and the TypeError is
being generated (and not caught) somewhere further down.
More information about the Python-list
mailing list