[Python-ideas] Bring back callable()

MRAB python at mrabarnett.plus.com
Wed Nov 24 00:50:10 CET 2010


On 23/11/2010 23:29, Chris Rebert wrote:
> On Tue, Nov 23, 2010 at 3:01 PM, Antoine Pitrou<solipsis at pitrou.net>  wrote:
>> Hello,
>>
>> Python 3 has removed callable() under the justification that's it's not
>> very useful and duck typing (EAFP) should be used instead. However,
>> it has since been felt by many people that it was an annoying loss;
>> there are situations where you truly want to know whether something is a
>> callable without actually calling it (for example when writing
>> sophisticated decorators, or simply when you want to inform the user
>> of an API misuse).
>>
>> The substitute of writing `isinstance(x, collections.Callable)` is
>> not good, 1) because it's wordier 2) because collections is really not
>> an intuitive place where to look for a Callable ABC.
>>
>> So, I would advocate bringing back the callable() builtin, which was
>> easy to use, helpful and semantically sane.
>
> Perhaps it should also be renamed iscallable() for consistency with
> isinstance() and issubclass() and to free up the nice name "callable"
> for user use.
>
Seems reasonable to me.



More information about the Python-ideas mailing list