Thanks Andrew for the excellent analysis quoted below. Further 
comments interleaved with yours.


On Fri, May 08, 2020 at 05:40:31PM -0700, Andrew Barnert via Python-ideas wrote:

> If someone wants this proposal, it’s because they believe it’s _not_ a 
> misuse to use a tuple as a frozen list (or a list as a mutable tuple).
> 
> If someone doesn’t want this proposal, the most likely reason 
> (although admittedly there are others) is because they believe it _is_ 
> a misuse to use a tuple as a frozen list.

I don't think it is necessary to believe that it is *always* misuse, but 
only that it is *often* misuse and therefore `==` ought to take the 
conservative position and refuse to guess.

I expect that nearly every Python programmer of sufficient experience 
has used a tuple as a de facto "frozen list" because it works and 
practicality beats purity. But that doesn't mean that I want my 
namedtuple PlayerStats(STR=10, DEX=12, INT=13, CON=9, WIS=8, CHR=12) to 
compare equal to my list [10, 12, 13, 9, 8, 12] by default.


> It’s not always a misuse; it’s sometimes perfectly idiomatic to use a 
> tuple as an immutable hashable sequence. It doesn’t just happen to 
> 'work', it works, for principled reasons (tuple is a Sequence), and 
> this is a good thing.[1]
> 
> It’s just that it’s _also_ common (probably a lot more common, but 
> even that isn’t necessary) to use it as an anonymous struct.
> 
> So, the OP is right that (1,2,3)==[1,2,3] would sometimes be handy, 
> the opponents are right that it would often be misleading, and the 
> question isn’t which one is right, it’s just how often is often. And 
> the answer is obviously: often enough that it can’t be ignored. And 
> that’s all that matters here.

Yes, I think there's a genuine need here.


> And that’s why tuple is different from frozenset. Very few uses of 
> frozenset are as something other than a frozen set, so it’s almost 
> never misleading that frozensets equal sets; plenty of tuples aren’t 
> frozen lists, so it would often be misleading if tuples equaled lists.


-- 
Steven
_______________________________________________
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/WXHODOZCS3HK2HOLZ2TQWAVYWBUWHDJV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to