On Fri, May 8, 2020 at 11:39 PM Steven D'Aprano <st...@pearwood.info> wrote:

> "More important" according to whose needs?
>

I dunno.  To mine? To "beginner programmers"? To numeric computation?

I can weaken my 'note' to 'purport' if that helps.

(3) Whereas the proposed duck-typing sequence equality relies on
>     the ordinary meaning of equality, applied element by element,
>     ignoring the type of the containers.
>

I think this one is our main disagreement.  I think a meaning for
"equality" in which a tuple is equal (equivalent) to a list with the same
items inside it is strikingly different from the ordinary meaning of
equality.  I don't deny that it is sometimes a useful question to ask, but
it is a new and different question than the one answered by '==' currently.

In my mind, this new kind of equality is MORE DIFFERENT from the current
meaning than would be case-folded equivalence of strings, for example.


> (1) They require a specialised equivalence relation apart from
>     `==`. Such as math.isclose(), a case insensitive comparison,
>     a JSON comparison.
>

Actually, this could perfectly well live on the types rather than in the
modules.  I mean, I could do it today by defining .__eq__() on some
subclasses of strings, floats, dicts, etc. if I wanted to.

But hypothetically (I'm not proposing this), we could also define new
operators .__eq2__(), .__eq3__(), etc. that would be called when Python
programmers used the operators `===`, `====`, etc.  With these new
operators in hand, we might give meanings to these new kinds of equivalence:

(1, 2, 3) === [1, 2, 3]   # has_same_items()
"David" === "daviD"   # a.upper() == b.upper()
"David" ==== "dabit"  # soundex(a, b)
3.14159265 === 3.14159266  # math.isclose(a, b)

It's competely general in a way that the other equivalences aren't.
>

Umm... no, it's really not.  It's a special kind of equivalence that I
guess applies to the Sequence ABC.  Or maybe the Collection ABC? But to be
really useful, it probably needs to work with things that don't register
those ABCs themselves.  I would surly expect:

(1, 2, 3) === np.array([1, 2, 3])

Also, if this were a thing.  But what about dicts, which are now ordered,
and hence sequence-like? Or dict.keys() if not the dict itself?

I'm sure reasonable answers could be decided for questions like that, but
this is FAR from "completely general" or a transparent extension of current
equality.

-- 
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
_______________________________________________
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/65HOMBTHFFVDZ4S4WDFFYCLEJKRU7N4O/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to