[Python-ideas] Why is there a callable predicate, but no iterable?

Terry Reedy tjreedy at udel.edu
Sun Sep 27 03:58:24 CEST 2009


Georg Brandl wrote:
> Terry Reedy schrieb:
>> Andrey Fedorov wrote:
>>
>>> What is the tradeoff between hasattr(f, '__call__')
>> I know about that ;-)
>>
>>> and isinstance(f, Callable)?
>> New to me ;-)
>> I presume it needs an import.

I checked, and it does.

>> I presume it also requires that something be registered as a Callable.
> 
> Nope; it uses the new instance/subclass inquiry hooks to pretend all objects
> having a __call__ attribute are instances of Callable.

Ok. I doubt 'instance inquiry hook' appears in the docs. I presume the 
documentation for the behavior is LibRef 8.3.1 and the table therein. It 
took me a few minutes to realize that "Abstract Methods" are the methods 
looked for in an isinstance enquiry and that "Mixin Methods" are the 
methods provided for 'free' when the ABC is used as a mixin (while the 
Abstract Methods must be explicitly instantiated). (Correct?) Perhaps 
this could be stated more directly just below the table.

There is no mention of ABC usage with issubclass, so I no idea what you 
mean there.

tjr




More information about the Python-ideas mailing list