Boris Borcic a écrit :
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.

Oops, looks like I failed to read enough of the thread and missed the point. Sorry.

Anyway...

*If* Python was to grow an infix operator for isinstance, then I'd indeed rather use 'in' than 'is' (FWIW I'd even prefer an 'isa' operator, but...)

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,

For which definition of "rare" ?

and so is testing class identity in its context.


* "x is None" is arguably

very arguably...

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

s/constant/object/

that

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

And ? How does it make it less a 'true use case' ???

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

but are not idiomatic, and way slower.

FWIW, you didn't adress the use of a _marker sentinel object (another common use case - at least in quite a lot of library code I've been reading so far). And FWIW, I so far use 'is' *way* more often than 'isinstance' (while this indeed may change with ABCs...).

Ok, you can clearly count me -10 wrt/ "stealing" the identity operator. If it matters, I'm -0 about using 'in' instead - at least, it makes sense wrt/ the semantics of 'in'. As far as I'm concerned, and if we really need an operator here, I'd prefer a new 'isa' one.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to