[Datetime-SIG] Another round on error-checking
alexander.belopolsky at gmail.com
Mon Aug 31 21:33:21 CEST 2015
On Mon, Aug 31, 2015 at 3:20 PM, Tim Peters <tim.peters at gmail.com> wrote:
> def __hash__(self):
> if self._hashcode == -1:
> tzoff = self.utcoffset()
> if tzoff is None:
> self._hashcode =
> days = _ymd2ord(self.year, self.month, self.day)
> seconds = self.hour * 3600 + self.minute * 60 + self.second
> self._hashcode = hash(timedelta(days, seconds,
> self.microsecond) - tzoff)
> return self._hashcode
> So it's the case that two datetimes that compare true may have
> different hashes, when they represent the earlier and later times in a
> fold. I didn't say "it's a puzzle" lightly ;-)
Yes, it looks like I have a bug there, but isn't fixing it just a matter of
moving self.replace(first=True) up two lines? Is there a bigger puzzle?
Certainly x == y ⇒ hash(x) == hash(y) is the implication that I intend to
preserve in all cases.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Datetime-SIG