[Datetime-SIG] PEP 495: What's left to resolve
tim.peters at gmail.com
Tue Sep 8 19:50:22 CEST 2015
>>> def __eq__(self, other):
>>> n_self = self.replace(tzinfo=None)
>>> n_other = other.replace(tzinfo=None)
>>> if self.tzinfo is other.tzinfo:
>>> return n_self == n_other
>> Well, that's infinite recursion - but I know what you mean ;-)
> No. You've probably missed that n_ objects are naive and naive comparison
> is just your plain old fold-unaware compare-all-components -except-fold
I assumed you were showing an implementation of datetime.__eq__. Yes?
In that case, `self` and `other` may both be naive on entry. Then
the first two lines effectively make exactly copies of them. Since
None is None, the `self.tzinfo is other.tzinfo` check succeeds, and so
goes on to compare n_self to n_other - which are exact copies of the
original inputs. Lather, rinse, repeat.
>>> u_self = n_self - self.utcoffset()
>>> v_self = n_self - self.replace(fold=(1-self.fold)).utcoffset()
>>> u_other = n_other - other.utcoffset()
>>> v_other = n_other - other.replace(fold=(1-self.fold)).utcoffset()
>>> return u_self == u_other == v_self == v_other
>> More infinite recursion.
More information about the Datetime-SIG