[issue37555] _CallList.__contains__ doesn't always respect ANY.

Karthikeyan Singaravelan report at bugs.python.org
Fri Jul 12 06:30:42 EDT 2019


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

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

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37555>
_______________________________________


More information about the Python-bugs-list mailing list