On Mon, Aug 31, 2015 at 4:38 PM, Tim Peters <tim.peters@gmail.com> wrote:
[Tim]
The easiest way out of this particular puzzle is, I believe, to say that two datetimes identical except for `fold` do _not_ compare equal. `fold` breaks the tie in the obvious way (the one with fold==1 is "greater").
[Alex]
I am afraid you are right, but proving that we will not break naive (fold unaware) programs will be harder in this case. Let me think some more about this.
Meanwhile, would you see any problem with not(x - y) not implying x == y?
Which is another puzzle :-( It's very intentional now that
dt1 == dt2 if and only if dt1 - dt2 == timedelta(0)
Here's a related puzzle, if comparison used `fold` to break ties:
y = x + timedelta(0)
If x had first=1, y will have fold=0, and then x != y.
In all, maybe it's better to leave __hash__ slightly broken.
After some thought, I believe the way to fix the implementation is what I suggested at first: reset fold to 0 before calling utcoffset() in __hash__. A rare hash collision is a small price to pay for having datetimes with different timezones in the same dictionary. Now, please, can we not start discussing how __hash__ should behave if utcoffset() raises a MissingTimeError?