ABCs -> infix syntax for isinstance() ?

Boris Borcic bborcic at gmail.com
Tue Oct 7 09:19:27 EDT 2008


Bruno Desthuilliers wrote:

>>> Boris Borcic a écrit :
>>>
>>>> Given the ABC innovation, maybe an infix syntax for isinstance() would
>>>> be good.
>>>> Possibilities :
>>>> - stealing "is" away from object identity. As a motivation, true use
>>>> cases for testing object identity are rare;

>>> "x is None" is a *very* common test. (...)
>>> Testing a class identity often happens when writing metaclasses

>> This kind-of-talks for Terry's proposition : adding a __contains__ to
>> type,

> I said "type identity testing", not isinstance() or issubclass() testing.

Yes, but in the thread's context [of choosing between "is" and "in" as infix 
syntax for isinstance()] you were in effect raising as an objection to the first 
choice that it meant conflict with this use case [of "type identity testing" 
which is "common when writing metaclasses"].

This implied "writing metaclasses" as a background experience to decide the 
issue, what in turn implied a preference for the second solution ("x in Number") 
on *two* counts.

First because it was a proposed alternative to what you were objecting to, and
Second because "x in Number" has this most simple "metaclassy" solution.

(...)
> 
> And anyway, I don't see how any of the above address the point that your 
> premise that "true identity testing is rare" is just wrong...
> 

I wrote "true use cases for identity testing are rare", it was more of an 
auxiliary assertion that a premise, and nothing you objected really disproved it 
(for an adequate definition of "true use case").

* writing metaclasses is rare, and so is testing class identity in its context.

* "x is None" is arguably not a "true use case", in the sense that it is a case 
of testing identity against a constant that

- doesn't compare equal to anything else
- is the single instance of a singleton class

so that there exists both an equality test and an isinstance() test that are 
equivalents to the identity test.

Cheers, BB









More information about the Python-list mailing list