'isa' keyword

Fuzzyman fuzzymanNO at SPAMvoidspaceDOTorg.uk
Thu Sep 1 08:28:04 EDT 2005


On 1 Sep 2005 00:52:54 -0700, "talin at acm dot org"
<viridia at gmail.com> wrote:

>Although I realize the perils of even suggesting polluting the Python
>namespace with a new keyword, I often think that it would be useful to
>consider defining an operator for testing whether or not an item is a
>member of a category.
>
>Currently, we have the 'in' operator, which tests for membership within
>a container, and that works very well -- in particular, it allows such
>membership tests to be expressed in very natural way. So for example,
>whereas in C++ I always have to say:
>
>    if (dependencies.find( name ) != dependencies.end())
>
>in Python I can simply say:
>
>    if name in dependencies:
>
>...which is much more readable and intuitive. At the same time,
>however, I recognize that there is a logical difference between
>membership in a container, and membership in a category. For example,
>although a bear is a member of the class of mammals, it doesn't make as
>much to say "if bear in mammal". Similarly, you wouldn't want to use
>the 'in' keyword as a replacement for isinstance(), i.e. "if name in
>str".
>
>I propose the word 'isa' because the term 'isa hierarchy' is commonly
>used to indicate a tree of types. So the syntax would look like this:
>
>    if bear isa mammal:
>    if name isa str:
>

What's the difference between this and ``isinstance`` ?


Best Regards,

Fuzzy
http://www.voidspace.org.uk/python



More information about the Python-list mailing list