On Sat, May 9, 2020 at 4:43 AM Dan Sommers
<2qdxy4rzwzuui...@potatochowder.com> wrote:
>
> On Sat, 9 May 2020 03:01:15 +1000
> Steven D'Aprano <st...@pearwood.info> wrote:
>
> > On Thu, May 07, 2020 at 11:04:16AM -0400, Dan Sommers wrote:
> > > On Thu, 7 May 2020 21:18:16 +1000
> > > Steven D'Aprano <st...@pearwood.info> wrote:
> > >
> > > > > The strongest equality is the "is" operator
> > > >
> > > > Please don't encourage the conceptual error of thinking of `is` as
> > > > *equality*, not even a kind of equality. It doesn't check for equality,
> > > > it checks for *identity* and we know that there is at least one object
> > > > in Python where identical objects aren't equal:
> > > >
> > > >     py> from math import nan
> > > >     py> nan is nan
> > > >     True
> > > >     py> nan == nan
> > > >     False
> > >
> > > We'd better agree to disagree on this one.
> >
> > Why? In what way is there any room for disagreement at all?
>
> I believe that the "is" operator is a test for some kind of equality,
> and you apparently don't.
>
> > * some equal objects are not identical;
> > * and some identical objects are not equal.
> >
> > It is a matter of fact that in Python `is` tests for object identity,
> > not equality:
> >
> > https://docs.python.org/3/reference/expressions.html#is-not
>
> Section 6.10 is entitled Comparisons, and lists both "is" and "==" as
> comparison operators.
>
> I admit that my use of the word "strongest" (to describe the "is"
> operator) and my conceptual ordering of different kinds of equality
> fails in the light of NaNs.  Curse you, IEEE Floating Point!  :-)
>
> Then again, that same documentation states "User-defined classes that
> customize their comparison behavior should follow some consistency
> rules, if possible."  One of the consistency rules is "Equality
> comparison should be reflexive. In other words, identical objects should
> compare equal," and that rule is summarized as "x is y implies x == y."
>
> So I'm not the only one who thinks of "is" as a kind of equality.  :-)
>

The documentation doesn't say that "is" represents equality, but only
that, in general, an object should be equal to itself. Identity is
still a completely separate concept to equality.

There's a concept of "container equality" that is expressed as "x is y
or x == y", but that's still a form of equality check. "x is y" on its
own is not an equality check. It's an identity check. Obviously it's a
comparison, but so are many other things :)

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UP3ZX5GLQFTF6UFMH64KGUJIO5JVSFFV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to