Skip to content

Commit a8bf860

Browse files
committed
gh-152315: Clarify missing self heuristic
1 parent 5519866 commit a8bf860

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
@@ -1679,10 +1679,13 @@ suggest_missing_self(PyFunctionObject *func, PyCodeObject *co,
16791679

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

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

0 commit comments

Comments
 (0)