diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-07-31 09:18:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-31 09:18:24 +0300 |
commit | ac20e0f98d6727ba97a9575bfa2a11b2f6247c35 (patch) | |
tree | 3b7938d610796051659b1b6fff27387a731c934c /Objects/classobject.c | |
parent | bpo-27671: Update FAQ about why len is function (GH-8432) (diff) | |
download | cpython-ac20e0f98d6727ba97a9575bfa2a11b2f6247c35.tar.gz cpython-ac20e0f98d6727ba97a9575bfa2a11b2f6247c35.tar.bz2 cpython-ac20e0f98d6727ba97a9575bfa2a11b2f6247c35.zip |
bpo-1617161: Make the hash and equality of methods not depending on the value of self. (GH-7848)
* The hash of BuiltinMethodType instances no longer depends on the hash
of __self__. It depends now on the hash of id(__self__).
* The hash and equality of ModuleType and MethodWrapperType instances no
longer depend on the hash and equality of __self__. They depend now on
the hash and equality of id(__self__).
* MethodWrapperType instances no longer support ordering.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r-- | Objects/classobject.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 095b0cad2b5..a193ada6d44 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -225,13 +225,9 @@ method_richcompare(PyObject *self, PyObject *other, int op) b = (PyMethodObject *)other; eq = PyObject_RichCompareBool(a->im_func, b->im_func, Py_EQ); if (eq == 1) { - if (a->im_self == NULL || b->im_self == NULL) - eq = a->im_self == b->im_self; - else - eq = PyObject_RichCompareBool(a->im_self, b->im_self, - Py_EQ); + eq = (a->im_self == b->im_self); } - if (eq < 0) + else if (eq < 0) return NULL; if (op == Py_EQ) res = eq ? Py_True : Py_False; @@ -274,11 +270,9 @@ method_hash(PyMethodObject *a) { Py_hash_t x, y; if (a->im_self == NULL) - x = PyObject_Hash(Py_None); + x = _Py_HashPointer(Py_None); else - x = PyObject_Hash(a->im_self); - if (x == -1) - return -1; + x = _Py_HashPointer(a->im_self); y = PyObject_Hash(a->im_func); if (y == -1) return -1; |