Author abarry
Recipients Hamish Campbell, abarry, docs@python
Date 2016-01-06.03:40:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1452051653.27.0.874198643731.issue26020@psf.upfronthosting.co.za>
In-reply-to
Content
Set displays appear to be the culprit here:

>>> class A:
...   count = 0
...   def __init__(self):
...     self.cnt = self.count
...     type(self).count += 1
...   def __eq__(self, other):
...     return type(self) is type(other)
...   def __hash__(self):
...     return id(type(self))
...
>>> e={A(), A(), A(), A(), A()}
>>> e
{<__main__.A object at 0x002BB2B0>}
>>> list(e)[0].cnt
4
>>> list(e)[0].count
5
>>> A.count = 0
>>> q=set([A(), A(), A(), A(), A()])
>>> q
{<__main__.A object at 0x002BB310>}
>>> list(q)[0].cnt
0
>>> list(q)[0].count
5

I'm guessing this is an optimization and/or set displays just don't keep ordering at definition time.

Do you have a use case where `x == y`/`hash(x) == hash(y)` does not mean that `x` and `y` should be interchangeable? True and 1 are 100% interchangeable, minus their str() output, and my example is very unlikely to ever appear in actual code.

Probably just better to fix the docs to specify that sets literals don't check ordering.
History
Date User Action Args
2016-01-06 03:40:53abarrysetrecipients: + abarry, docs@python, Hamish Campbell
2016-01-06 03:40:53abarrysetmessageid: <1452051653.27.0.874198643731.issue26020@psf.upfronthosting.co.za>
2016-01-06 03:40:53abarrylinkissue26020 messages
2016-01-06 03:40:52abarrycreate