Skip to content

Commit 2b80cb2

Browse files
committed
gh-152315: Clarify missing self heuristic
1 parent f4669fa commit 2b80cb2

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Python/ceval.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,10 +1678,13 @@ suggest_missing_self(PyFunctionObject *func, PyCodeObject *co,
16781678

16791679
PyObject *first_argument = PyStackRef_AsPyObjectBorrow(args[0]);
16801680
if (first_argument == NULL || PyType_Check(first_argument)) {
1681+
// When first arg is NULL, it's not really about self
1682+
// If its a type object, then its a classmethod.
16811683
return 0;
16821684
}
16831685

16841686
if (co->co_argcount > 0) {
1687+
// don't confuse the user when they've already declared a common convention of cls/self
16851688
PyObject *first_parameter_name = PyTuple_GET_ITEM(co->co_localsplusnames, 0);
16861689
/* If the receiver parameter is already declared, another hint would be misleading. */
16871690
if (PyUnicode_CompareWithASCIIString(first_parameter_name, "self") == 0 ||
@@ -1690,7 +1693,7 @@ suggest_missing_self(PyFunctionObject *func, PyCodeObject *co,
16901693
return 0;
16911694
}
16921695
}
1693-
1696+
// If the current function matches on the type, its likely worth adding the hint
16941697
PyTypeObject *self_cls = Py_TYPE(first_argument);
16951698
PyFunctionObject *possibly_current_function =
16961699
(PyFunctionObject *)_PyType_Lookup(self_cls, co->co_name);

0 commit comments

Comments
 (0)