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. Regards Antoine.
On 23 November 2010 23:01, Antoine Pitrou <solipsis@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.
+1 I find it useful in Python 2. You have to know its limitations, but it is still useful. Michael
Regards
Antoine.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
I admit defeat on this one. On Tue, Nov 23, 2010 at 3:14 PM, Michael Foord <fuzzyman@voidspace.org.uk> wrote:
On 23 November 2010 23:01, Antoine Pitrou <solipsis@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.
+1 I find it useful in Python 2. You have to know its limitations, but it is still useful.
Michael
Regards
Antoine.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- http://www.voidspace.org.uk
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- --Guido van Rossum (python.org/~guido)
Falls under "no new builtins" though. Georg Am 24.11.2010 00:19, schrieb Guido van Rossum:
I admit defeat on this one.
On Tue, Nov 23, 2010 at 3:14 PM, Michael Foord <fuzzyman@voidspace.org.uk> wrote:
On 23 November 2010 23:01, Antoine Pitrou <solipsis@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.
+1 I find it useful in Python 2. You have to know its limitations, but it is still useful.
Michael
Regards
Antoine.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- http://www.voidspace.org.uk
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
On 24/11/2010 10:59, Georg Brandl wrote:
Falls under "no new builtins" though.
It's not really new because it's in Python 2. :-)
Georg
Am 24.11.2010 00:19, schrieb Guido van Rossum:
I admit defeat on this one.
On Tue, Nov 23, 2010 at 3:14 PM, Michael Foord <fuzzyman@voidspace.org.uk> wrote:
On 23 November 2010 23:01, Antoine Pitrou<solipsis@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.
+1 I find it useful in Python 2. You have to know its limitations, but it is still useful.
On Tue, 23 Nov 2010 15:15:46 -0800 Alexandre Conrad <alexandre.conrad@gmail.com> wrote:
2010/11/23 Antoine Pitrou <solipsis@pitrou.net>:
So, I would advocate bringing back the callable() builtin, which was easy to use, helpful and semantically sane.
What about:
hasattr(obj, '__call__')
It's not the right code. You can take a look at the implementation of Callable.__subclasshook__ here: http://code.python.org/hg/branches/py3k/file/tip/Lib/_abcoll.py#l139 Regards Antoine.
On Tue, Nov 23, 2010 at 3:01 PM, Antoine Pitrou <solipsis@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. Cheers, Chris -- http://blog.rebertia.com
On 23/11/2010 23:29, Chris Rebert wrote:
On Tue, Nov 23, 2010 at 3:01 PM, Antoine Pitrou<solipsis@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.
Chris Rebert <pyideas@...> writes:
Perhaps it should also be renamed iscallable() for consistency with isinstance() and issubclass() and to free up the nice name "callable" for user use.
Let's not. We shouldn't make it anymore difficult to cope with having a gap of no callable() by renaming it. Anyway, they're different kinds of words. "instance()" or "subclass()" wouldn't make any sense.
On 11/23/2010 6:01 PM, Antoine Pitrou wrote:
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.
I thnk it should be in the abc module, along with WeakSet The funny thing is that your rationale for not adding Picklable (just try and catch exception) is essentially the rationale for removing callable() ;-). -- Terry Jan Reedy
On Tue, 23 Nov 2010 18:50:13 -0500 Terry Reedy <tjreedy@udel.edu> wrote:
On 11/23/2010 6:01 PM, Antoine Pitrou wrote:
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.
I thnk it should be in the abc module, along with WeakSet
The funny thing is that your rationale for not adding Picklable (just try and catch exception) is essentially the rationale for removing callable() ;-).
Well, I have never needed to know in advance whether an object was picklable or not, while knowing whether it's callable has come often. Regards Antoine.
Terry Reedy <tjreedy@udel.edu> wrote:
On 11/23/2010 6:01 PM, Antoine Pitrou wrote:
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.
I thnk it should be in the abc module, along with WeakSet
Me too. Bill
On Mon, Mar 7, 2011 at 2:17 PM, Bill Janssen <janssen@parc.com> wrote:
Terry Reedy <tjreedy@udel.edu> wrote:
On 11/23/2010 6:01 PM, Antoine Pitrou wrote:
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.
I thnk it should be in the abc module, along with WeakSet
Me too.
I was not around here, and although I looked for, I didn't find this on the web: What was the reasoning for removing "callable" in the first place? js -><-
Bill _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
On 7 March 2011 20:09, Joao S. O. Bueno <jsbueno@python.org.br> wrote:
On Mon, Mar 7, 2011 at 2:17 PM, Bill Janssen <janssen@parc.com> wrote:
Terry Reedy <tjreedy@udel.edu> wrote:
On 11/23/2010 6:01 PM, Antoine Pitrou wrote:
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.
I thnk it should be in the abc module, along with WeakSet
Me too.
Too late. :-)
I was not around here, and although I looked for, I didn't find this on the web:
What was the reasoning for removing "callable" in the first place?
It didn't always do exactly the right thing (but was usually "good enough") and was thought easy to replace with a more accurate alternative (isinstance(foo, abc.Callable) I *think*) which proved annoying in pactise. All the best, Michael js
-><-
Bill _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
-- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html
Michael Foord <fuzzyman@gmail.com> wrote:
I thnk it should be in the abc module, along with WeakSet
Me too.
Too late. :-)
My mail tool seems to have an instinctive sense of when I've not had coffee yet, and it takes that as an opportunity to show me old unread email from last year :-). Bill
On Tue, 8 Mar 2011 08:06:23 am Bill Janssen wrote:
Michael Foord <fuzzyman@gmail.com> wrote:
I thnk it should be in the abc module, along with WeakSet
Me too.
Too late. :-)
My mail tool seems to have an instinctive sense of when I've not had coffee yet, and it takes that as an opportunity to show me old unread email from last year :-).
It wasn't just you. I got it too. -- Steven D'Aprano
Antoine Pitrou <solipsis@...> writes:
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.
Antoine.
I actually really prefer `isinstance(x, collections.Callable)`... If this was accepted, I would at least want it to be called `iscallable` instead of `callable`, since I sometimes want to use the name `callable` in my code. Ram.
Ram Rachum wrote:
Antoine Pitrou <solipsis@...> writes:
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.
Antoine.
I actually really prefer `isinstance(x, collections.Callable)`...
If this was accepted, I would at least want it to be called `iscallable` instead of `callable`, since I sometimes want to use the name `callable` in my code.
That's still possible. callable() is a built-in function, not a keyword. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 24 2010)
Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/
M.-A. Lemburg <mal@...> writes:
Ram Rachum wrote:
If this was accepted, I would at least want it to be called `iscallable`
instead
of `callable`, since I sometimes want to use the name `callable` in my code.
That's still possible. callable() is a built-in function, not a keyword.
I know, but I really don't like overshadowing built-ins. Ram.
I actually really prefer `isinstance(x, collections.Callable)`...
If this was accepted, I would at least want it to be called `iscallable` instead of `callable`, since I sometimes want to use the name `callable` in my code.
Ram.
+1 to making a Callable abstract baseclass -1 to putting it in collections... it's not iterable nor does it hold items. -- Zachary Burns (407)590-4814 Aim - Zac256FL
participants (17)
-
Alexandre Conrad
-
Antoine Pitrou
-
Benjamin Peterson
-
Bill Janssen
-
Chris Rebert
-
Georg Brandl
-
Guido van Rossum
-
Joao S. O. Bueno
-
M.-A. Lemburg
-
Michael Foord
-
Michael Foord
-
MRAB
-
Ram Rachum
-
Robert Collins
-
Steven D'Aprano
-
Terry Reedy
-
Zac Burns