Skip to content

Commit 439cc12

Browse files
committed
Change methodology
1 parent 0a1fdb9 commit 439cc12

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Python/ceval.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,9 +1641,15 @@ too_many_positional(PyThreadState *tstate, PyCodeObject *co,
16411641
}
16421642

16431643
static int
1644-
suggest_missing_self(PyCodeObject *co, Py_ssize_t argcount)
1644+
suggest_missing_self(PyFunctionObject *func, PyCodeObject *co, _PyStackRef const *args, Py_ssize_t argcount)
16451645
{
1646-
return (co->co_argcount + 1) == argcount
1646+
if ((co->co_argcount + 1) != argcount || argcount == 0) {
1647+
return 0;
1648+
}
1649+
PyObject *first_argument = PyStackRef_AsPyObjectBorrow(args[0]);
1650+
PyTypeObject *self_cls = Py_TYPE(first_argument);
1651+
PyFunctionObject *possibly_current_function = (PyFunctionObject *) _PyType_Lookup(self_cls, co->co_name);
1652+
return possibly_current_function == func;
16471653
}
16481654

16491655
static int
@@ -1738,7 +1744,7 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
17381744

17391745
/* Copy all positional arguments into local variables */
17401746
Py_ssize_t j, n;
1741-
int missing_self_hint = suggest_missing_self(co, argcount);
1747+
int missing_self_hint = suggest_missing_self(func, co, args, argcount);
17421748
if (argcount > co->co_argcount) {
17431749
n = co->co_argcount;
17441750
}

0 commit comments

Comments
 (0)