summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMartijn Pieters <github.com@zopatista.com>2019-03-05 05:19:34 (GMT)
committerBenjamin Peterson <benjamin@python.org>2019-03-05 05:19:34 (GMT)
commitb727239575894b060db37792e86aab818c00817a (patch)
tree2da2cd225bbae5d92ccb9dee48afbb842dc9640d /Objects
parent0983fcd0d5bd00c6b0dd3040760226f67aa831cd (diff)
downloadcpython-b727239575894b060db37792e86aab818c00817a.zip
cpython-b727239575894b060db37792e86aab818c00817a.tar.gz
cpython-b727239575894b060db37792e86aab818c00817a.tar.bz2
closes bpo-36188: Clean up 'unbound' method left-overs. (GH-12169)
Methods are always bound, and `__self__` can no longer be `NULL` (`method_new()` and `PyMethod_New()` both explicitly check for this). Moreover, once a bound method is bound, it *stays* bound and won't be re-bound to something else, so the section in the datamodel that talks about accessing an methods in a different descriptor-binding context doesn't apply any more in Python 3.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/classobject.c21
1 files changed, 3 insertions, 18 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 0d1cf7a..1ee8978 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -267,10 +267,7 @@ static Py_hash_t
method_hash(PyMethodObject *a)
{
Py_hash_t x, y;
- if (a->im_self == NULL)
- x = _Py_HashPointer(Py_None);
- else
- x = _Py_HashPointer(a->im_self);
+ x = _Py_HashPointer(a->im_self);
y = PyObject_Hash(a->im_func);
if (y == -1)
return -1;
@@ -294,11 +291,6 @@ method_call(PyObject *method, PyObject *args, PyObject *kwargs)
PyObject *self, *func;
self = PyMethod_GET_SELF(method);
- if (self == NULL) {
- PyErr_BadInternalCall();
- return NULL;
- }
-
func = PyMethod_GET_FUNCTION(method);
return _PyObject_Call_Prepend(func, self, args, kwargs);
@@ -307,15 +299,8 @@ method_call(PyObject *method, PyObject *args, PyObject *kwargs)
static PyObject *
method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls)
{
- /* Don't rebind an already bound method of a class that's not a base
- class of cls. */
- if (PyMethod_GET_SELF(meth) != NULL) {
- /* Already bound */
- Py_INCREF(meth);
- return meth;
- }
- /* Bind it to obj */
- return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj);
+ Py_INCREF(meth);
+ return meth;
}
PyTypeObject PyMethod_Type = {