other ways to check for <type 'function'>?
JohnRoth1 at jhrothjr.com
Thu Nov 2 14:15:18 CET 2006
Fredrik Lundh wrote:
> elderic wrote:
> > are there other ways than the ones below to check for <type 'function'>
> > in a python script?
PEP 3100 specifies that the callable builtin is
to be removed in Python 3.0, together with what
I presume is the underlying C support for the
Unfortunately, there are cases where it's not
advisable to call something to verify that it's
callable - calling it will cause irreversable
changes to the program state, while a
verification function should make no changes
to state. The advice is fundamentally bad
On the other claw, I can understand Guido's
point in wanting to get rid of it - it's got to be
an ugly piece of code with the Inappropriate
Intimacy code smell stinking up the place.
So what to do? Frankly, I'd back up a few
yards and consider the system design.
Where is the callable coming from? If it's
inside the team's scope of control, don't
bother checking it - the team should have
tests in place that verify that each site
passing a callable is passing the correct
object. If it's coming from outside, define
what's allowable and check that case by
case, preferably with consultation with
your code's clients.
More information about the Python-list