On Mon, Aug 31, 2015 at 3:20 PM, Tim Peters <[email protected]> wrote:
> def __hash__(self): > if self._hashcode == -1: > tzoff = self.utcoffset() > if tzoff is None: > self._hashcode = > hash(self.replace(first=True)._getstate()[0]) > else: > 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.
_______________________________________________ Datetime-SIG mailing list [email protected] https://mail.python.org/mailman/listinfo/datetime-sig The PSF Code of Conduct applies to this mailing list: https://www.python.org/psf/codeofconduct/
