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:
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
Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
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.comwrote:
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:
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
Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- Gerald Britton
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:
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.
Nope; it uses the new instance/subclass inquiry hooks to pretend all objects having a __call__ attribute are instances of Callable.
Georg
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
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: http://www.python.org/dev/peps/pep-3119/#overloading-isinstance-and-issubcla...
Georg
On Fri, Sep 25, 2009 at 4:34 PM, Andrey Fedorov anfedorov@gmail.com wrote:
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?
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__')
- Andrey
Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
Cheers, Quentin