<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 31, 2015 at 4:38 PM, Tim Peters <span dir="ltr"><<a href="mailto:tim.peters@gmail.com" target="_blank">tim.peters@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":3do" class="a3s" style="overflow:hidden">[Tim]<br>
<span class="">>> The easiest way out of this particular puzzle is, I believe, to say<br>
>> that two datetimes identical except for `fold` do _not_ compare equal.<br>
>> `fold` breaks the tie in the obvious way (the one with fold==1 is<br>
>> "greater").<br>
<br>
</span>[Alex]<br>
<span class="">> I am afraid you are right, but proving that we will not break naive (fold<br>
> unaware) programs will be harder in this case.   Let me think some more<br>
> about this.<br>
><br>
> Meanwhile, would you see any problem with not(x - y) not implying x == y?<br>
<br>
</span>Which is another puzzle :-(  It's very intentional now that<br>
<br>
    dt1 == dt2 if and only if dt1 - dt2 == timedelta(0)<br>
<br>
Here's a related puzzle, if comparison used `fold` to break ties:<br>
<br>
    y = x + timedelta(0)<br>
<br>
If x had first=1, y will have fold=0, and then x != y.<br>
<br>
In all, maybe it's better to leave __hash__ slightly broken.</div></blockquote></div><div class="gmail_extra"><br></div>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.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Now, please, can we not start discussing how __hash__ should behave if utcoffset() raises a MissingTimeError?</div></div>