Need instruction on how to use isinstance

alex23 wuwei23 at gmail.com
Mon Jun 28 01:09:24 EDT 2010


Stephen Hansen <me+list/pyt... at 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.



More information about the Python-list mailing list