This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients belopolsky, p-ganssle, serhiy.storchaka, xtreak
Date 2019-07-13.05:25:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562995541.72.0.689612631399.issue37579@roundup.psfhosted.org>
In-reply-to
Content
As reported by Serhiy on https://bugs.python.org/issue37555#msg347733 there is a difference in __eq__ definition in datetime module's C and Python implementation for timedelta and time. When the other in __eq__ is not of the same type NotImplemented is not returned in Python implementation like C causing equality to behave differently.

Difference in C implementation and Python implementation for datetime.timedelta.__eq__

https://github.com/python/cpython/blob/c8e7146de257930ea8d0d4aa74b3a64fcaa79d4b/Modules/_datetimemodule.c#L2152

static PyObject *
delta_richcompare(PyObject *self, PyObject *other, int op)
{
    if (PyDelta_Check(other)) {
        int diff = delta_cmp(self, other);
        return diff_to_bool(diff, op);
    }
    else {
        Py_RETURN_NOTIMPLEMENTED;
    }
}


https://github.com/python/cpython/blob/c8e7146de257930ea8d0d4aa74b3a64fcaa79d4b/Lib/datetime.py#L732

def __eq__(self, other):
    if isinstance(other, timedelta):
        return self._cmp(other) == 0
    else:
        return False


I will add a PR for this with test.
History
Date User Action Args
2019-07-13 05:25:41xtreaksetrecipients: + xtreak, belopolsky, serhiy.storchaka, p-ganssle
2019-07-13 05:25:41xtreaksetmessageid: <1562995541.72.0.689612631399.issue37579@roundup.psfhosted.org>
2019-07-13 05:25:41xtreaklinkissue37579 messages
2019-07-13 05:25:41xtreakcreate