From: alex23 on
Stephen Hansen <me+list/pyt...(a)ixokai.io> wrote:
> P.S. The removal of callable is something I don't understand in Python
> 3: while generally speaking I do really believe and use duck typing, I
> too have on occassion wanted to dispatch based on 'is callable? do x'.
> Sometimes its not convenient to do so via duck typing. Its rare. But it
> is there. That isinstance()/issubclass got a boost in power with the
> ABC's and registering, while at the same time the ability to introspect
> about the function-y callable-y ness of a function was removed? Makes no
> sense to me. But alas!

There's always: isinstance(<object>, collections.Callable)
From: Chris Rebert on
On Sun, Jun 27, 2010 at 9:30 PM, alex23 <wuwei23(a)gmail.com> wrote:
> Stephen Hansen <me+list/pyt...(a)ixokai.io> wrote:
>> P.S. The removal of callable is something I don't understand in Python
>> 3: while generally speaking I do really believe and use duck typing, I
>> too have on occassion wanted to dispatch based on 'is callable? do x'.
>> Sometimes its not convenient to do so via duck typing. Its rare. But it
>> is there. That isinstance()/issubclass got a boost in power with the
>> ABC's and registering, while at the same time the ability to introspect
>> about the function-y callable-y ness of a function was removed? Makes no
>> sense to me. But alas!
>
> There's always: isinstance(<object>, collections.Callable)

Why in Guido's name is that in the collections module of all places?
What hath callability to do with container objects?

Cheers,
Chris
--
http://blog.rebertia.com
From: Stephen Hansen on
On 6/27/10 9:30 PM, alex23 wrote:
> Stephen Hansen<me+list/pyt...(a)ixokai.io> wrote:
>> P.S. The removal of callable is something I don't understand in Python
>> 3: while generally speaking I do really believe and use duck typing, I
>> too have on occassion wanted to dispatch based on 'is callable? do x'.
>> Sometimes its not convenient to do so via duck typing. Its rare. But it
>> is there. That isinstance()/issubclass got a boost in power with the
>> ABC's and registering, while at the same time the ability to introspect
>> about the function-y callable-y ness of a function was removed? Makes no
>> sense to me. But alas!
>
> There's always: isinstance(<object>, collections.Callable)

What the hell? When did that show up? o.O (Did I not pay attention
enough during the ABC conversations? It seemed so boring).

A) how is Callable a collection, in any way shape or form? And B) does
that really return True for everything callable-esque? (I don't have a
3.x to play with on this temporary computer)

--

... Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/

From: Stephen Hansen on
On 6/27/10 9:47 PM, Chris Rebert wrote:
>> There's always: isinstance(<object>, collections.Callable)
>
> Why in Guido's name is that in the collections module of all places?
> What hath callability to do with container objects?

What he said! Minus the blasphemy.

It's Benevolent _Dictator_ For Life. Not Benevolent _Diety_ For Life.
Just because a man has an uncanny sense of style (in the programming
sense) and a time machine, doesn't a god make.

--

... Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/

From: alex23 on
Stephen Hansen <me+list/pyt...(a)ixokai.io> wrote:
> What the hell? When did that show up? o.O (Did I not pay attention
> enough during the ABC conversations? It seemed so boring).

The PEPs & post-release docs detailing Py3 changes were worth reading,
it's noted in the sections on changes to built-ins:

http://www.python.org/dev/peps/pep-3100/
http://docs.python.org/py3k/whatsnew/3.0.html

> A) how is Callable a collection, in any way shape or form? And B) does
> that really return True for everything callable-esque? (I don't have a
> 3.x to play with on this temporary computer)

A) I was tempted to say "it's a collection of code" :) But really, the
role of the collections model has expanded in 3.x to also provide a
repository for ABCs:

"In addition to containers, the collections module provides some ABCs
(abstract base classes) that can be used to test whether a class
provides a particular interface, for example, whether it is hashable
or a mapping."

http://docs.python.org/py3k/library/collections.html

B) In a quick test in 3.1.2, it returned true for a function, a bound
and unbound lambda, and an instance of a class with a __call__
defined. If there's any other kind of callable you can think of, let
me know and I'll be happy to test it.