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

Georg Brandl g.brandl at gmx.net
Sun Sep 27 10:20:12 CEST 2009

Terry Reedy schrieb:
> 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.

Yes, that's correct, and it should indeed be noted there.

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

It's best described in the PEP:


Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

More information about the Python-ideas mailing list