| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1678,10 +1678,13 @@ suggest_missing_self(PyFunctionObject *func, PyCodeObject *co, | |||
| 1678 | 1678 | ||
| 1679 | 1679 | PyObject *first_argument = PyStackRef_AsPyObjectBorrow(args[0]); | |
| 1680 | 1680 | 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. | ||
| 1681 | 1683 | return 0; | |
| 1682 | 1684 | } | |
| 1683 | 1685 | ||
| 1684 | 1686 | if (co->co_argcount > 0) { | |
| 1687 | + // don't confuse the user when they've already declared a common convention of cls/self | ||
| 1685 | 1688 | PyObject *first_parameter_name = PyTuple_GET_ITEM(co->co_localsplusnames, 0); | |
| 1686 | 1689 | /* If the receiver parameter is already declared, another hint would be misleading. */ | |
| 1687 | 1690 | if (PyUnicode_CompareWithASCIIString(first_parameter_name, "self") == 0 || | |
@@ -1690,7 +1693,7 @@ suggest_missing_self(PyFunctionObject *func, PyCodeObject *co, | |||
| 1690 | 1693 | return 0; | |
| 1691 | 1694 | } | |
| 1692 | 1695 | } | |
| 1693 | - | ||
| 1696 | + // If the current function matches on the type, its likely worth adding the hint | ||
| 1694 | 1697 | PyTypeObject *self_cls = Py_TYPE(first_argument); | |
| 1695 | 1698 | PyFunctionObject *possibly_current_function = | |
| 1696 | 1699 | (PyFunctionObject *)_PyType_Lookup(self_cls, co->co_name); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments