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 ElizabethU, serhiy.storchaka, xtreak
Date 2019-07-12.10:30:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562927442.92.0.224134742223.issue37555@roundup.psfhosted.org>
In-reply-to
Content
Good catch, commenting out the c implementation of datetime in setup.py I can see the following difference.

➜  cpython git:(master) ✗ ./python.exe
Python 3.9.0a0 (heads/master-dirty:c8e7146de2, Jul 12 2019, 15:51:00)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime, sys, unittest.mock
>>> datetime.timedelta(seconds=1) == unittest.mock.ANY
False

➜  cpython git:(master) ✗ python3.7
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime, sys, unittest.mock
>>> datetime.timedelta(seconds=1) == unittest.mock.ANY
True

The C implementation and Python are different for timedelta__eq__ as mentioned with datetime.__eq__ being same and correct in NotImplementedError.

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
History
Date User Action Args
2019-07-12 10:30:42xtreaksetrecipients: + xtreak, serhiy.storchaka, ElizabethU
2019-07-12 10:30:42xtreaksetmessageid: <1562927442.92.0.224134742223.issue37555@roundup.psfhosted.org>
2019-07-12 10:30:42xtreaklinkissue37555 messages
2019-07-12 10:30:42xtreakcreate