[Python-3000] callable()

Andrew Koenig ark at acm.org
Mon Jul 17 18:19:44 CEST 2006


I note in PEP 3000 the proposal to remove callable(), with the comment "just
call the object and catch the exception."

I think that's a bad idea, because it takes away the ability to separate the
callability test from the first call.  As a simple example, suppose you're
writing a function that you expect to be given a function as one of its
arguments:

	def foo(bar, fun):
		assert callable(fun)
		# ...

It might be that foo doesn't actually call fun until much later.
Nevertheless, from a testing viewpoint, it would be better to detect the
error immediately of passing something that can't be called.

If you didn't have callable, how would you write this example?




More information about the Python-3000 mailing list