[Python-3000] callable()

Michael Urman murman at gmail.com
Tue Jul 18 15:45:27 CEST 2006


On 7/18/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> I think that should be amended to "just use hasattr(obj. '__call__')
> instead". That's what callable() will become equivalent to once
> old_style classes are gone.
>
> Then it becomes a matter of whether it's worth having callable()
> around as an alternative spelling. Those arguing in favour of
> it would have to explain whether we should also have addable(),
> subtractable(), mutiplyable(), indexable(), etc. etc. etc...

I think if the proponents of removing callable had made it more
obvious that hasatr(obj, '__call__') was a relatively equivalent
option which served to make it obvious what its limitations were,
there would have been fewer objections. Then I personally find the
intent indication of callable(obj) vs hasattr(obj, '__call__') to be a
good trade.

As for callable() vs addable(), etc., the reason is obvious. Function
calls very commonly have large side effects and are only rarely
idempotent. The operations you mention are expected to have no side
effects on the object. This makes a try/except much more palatable for
addition, subscripting, etc. than for calling a function.

Michael
-- 
Michael Urman  http://www.tortall.net/mu/blog


More information about the Python-3000 mailing list