
So there was a discussion back in April [0] about the lack of an "iterable" predicate, which Pascal pointing out that the intention may be to use "isinstance(obj, Iterable)" instead. That seems inconsistent with the existence of collections.Callable (so, isinstance(obj, Callable) instead of callable(obj)). Which direction is this more likely to be resolved? Should I write iterable(obj) or expect callable(obj) to be deprecated? - Andrey 0. http://mail.python.org/pipermail/python-ideas/2009-April/004382.html

I think callable() was removed in 3.x: http://docs.python.org/3.1/whatsnew/3.0.html?highlight=callable On Fri, Sep 25, 2009 at 10:34 AM, Andrey Fedorov <anfedorov@gmail.com> wrote:
-- Gerald Britton

Aha, indeed! Removed callable(). Instead of callable(f) you can use hasattr(f,
'__call__'). The operator.isCallable() function is also gone.
What is the tradeoff between hasattr(f, '__call__') and isinstance(f, Callable)? - Andrey On Fri, Sep 25, 2009 at 10:39 AM, Gerald Britton <gerald.britton@gmail.com>wrote:

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 presume it also requires that something be registered as a Callable. Terry Jan Reedy

Terry Reedy schrieb:
Nope; it uses the new instance/subclass inquiry hooks to pretend all objects having a __call__ attribute are instances of Callable. Georg -- 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.

Georg Brandl wrote:
I checked, and it does.
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

Terry Reedy schrieb:
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: http://www.python.org/dev/peps/pep-3119/#overloading-isinstance-and-issubcla... Georg -- 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.

On Fri, Sep 25, 2009 at 4:34 PM, Andrey Fedorov <anfedorov@gmail.com> wrote:
The latter : callable() has been removed in Python 3 and the new way is to check the existence of the __call__() method => hasattr(obj, '__call__')
Cheers, Quentin

I think callable() was removed in 3.x: http://docs.python.org/3.1/whatsnew/3.0.html?highlight=callable On Fri, Sep 25, 2009 at 10:34 AM, Andrey Fedorov <anfedorov@gmail.com> wrote:
-- Gerald Britton

Aha, indeed! Removed callable(). Instead of callable(f) you can use hasattr(f,
'__call__'). The operator.isCallable() function is also gone.
What is the tradeoff between hasattr(f, '__call__') and isinstance(f, Callable)? - Andrey On Fri, Sep 25, 2009 at 10:39 AM, Gerald Britton <gerald.britton@gmail.com>wrote:

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 presume it also requires that something be registered as a Callable. Terry Jan Reedy

Terry Reedy schrieb:
Nope; it uses the new instance/subclass inquiry hooks to pretend all objects having a __call__ attribute are instances of Callable. Georg -- 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.

Georg Brandl wrote:
I checked, and it does.
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

Terry Reedy schrieb:
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: http://www.python.org/dev/peps/pep-3119/#overloading-isinstance-and-issubcla... Georg -- 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.

On Fri, Sep 25, 2009 at 4:34 PM, Andrey Fedorov <anfedorov@gmail.com> wrote:
The latter : callable() has been removed in Python 3 and the new way is to check the existence of the __call__() method => hasattr(obj, '__call__')
Cheers, Quentin
participants (5)
-
Andrey Fedorov
-
Georg Brandl
-
Gerald Britton
-
Quentin Gallet-Gilles
-
Terry Reedy