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.

Title: Difference in equality check between C and Python implementation for datetime module's timedelta and time
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, miss-islington, p-ganssle, serhiy.storchaka, xtreak
Priority: normal Keywords: patch

Created on 2019-07-13 05:25 by xtreak, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14726 merged xtreak, 2019-07-13 05:36
PR 14743 merged miss-islington, 2019-07-13 13:37
PR 14745 merged xtreak, 2019-07-13 13:43
Messages (6)
msg347773 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-07-13 05:25
As reported by Serhiy on 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__

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 {

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

I will add a PR for this with test.
msg347813 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-07-13 13:15
Do you mind to fix also other similar cases if they are? __lt__ and others should have the same property.
msg347815 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2019-07-13 13:22
New changeset e6b46aafad3427463d6264a68824df4797e682f1 by Paul Ganssle (Xtreak) in branch 'master':
bpo-37579: Improve equality behavior for pure Python datetime and time (GH-14726)
msg347821 - (view) Author: miss-islington (miss-islington) Date: 2019-07-13 13:59
New changeset 143672cf028740fc549e532c049559c522930c95 by Miss Islington (bot) in branch '3.8':
bpo-37579: Improve equality behavior for pure Python datetime and time (GH-14726)
msg347903 - (view) Author: miss-islington (miss-islington) Date: 2019-07-14 10:14
New changeset c6b31061997526b31961ec34328408ca421f51fc by Miss Islington (bot) (Xtreak) in branch '3.7':
[3.7] bpo-37579: Improve equality behavior for pure Python datetime and time (GH-14726) (GH-14745)
msg348454 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-07-25 21:16
See issue37685.
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81760
2019-07-25 21:16:37serhiy.storchakasetmessages: + msg348454
2019-07-14 10:14:03miss-islingtonsetmessages: + msg347903
2019-07-14 10:04:38p-gansslesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-07-13 13:59:40miss-islingtonsetnosy: + miss-islington
messages: + msg347821
2019-07-13 13:43:16xtreaksetpull_requests: + pull_request14541
2019-07-13 13:37:44miss-islingtonsetpull_requests: + pull_request14539
2019-07-13 13:22:25p-gansslesetmessages: + msg347815
2019-07-13 13:15:52serhiy.storchakasetmessages: + msg347813
2019-07-13 05:36:56xtreaksetkeywords: + patch
stage: patch review
pull_requests: + pull_request14522
2019-07-13 05:25:41xtreakcreate