FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-42978: Improve error message when 'self' is missing from the method definition by pablogsal · Pull Request #24272 · python/cpython · GitHub

Repository navigation

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
fixup! Update Python/ceval.c
  • Loading branch information
pablogsal committed Jan 20, 2021
commit 219342afd605430f8ad043824a72a2ffbd69c899
28 changes: 13 additions & 15 deletions Python/ceval.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6015,32 +6015,30 @@ improve_missing_self_error(PyThreadState* tstate, PyCodeObject* co, Py_ssize_t n
if (nargs + 1 != co->co_argcount) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What about positional-only parameters and var-positional parameter?

pablogsal Jan 20, 2021 •
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I left that for future PRs, I wanted to get the basic logic first and then improve upon. But is just mirroring the logic in too_many_positional().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There is the check !(co->co_flags & CO_VARARGS) befory calling too_many_positional().

return;
}

PyObject *type, *val, *tb;
_PyErr_Fetch(tstate, &type, &val, &tb);

if (!PyUnicode_CheckExact(val)) {
goto exit;
}

if (co->co_argcount > 0 && co->co_varnames && PyTuple_GET_SIZE(co->co_varnames) > 0) {
PyObject* first_arg = PyTuple_GET_ITEM(co->co_varnames, 0);
int comp = PyUnicode_CompareWithASCIIString(first_arg, "self");
if (comp == 0 || comp == -1) {
if (_PyUnicode_EqualToASCIIString(first_arg, "self")) {
PyErr_Clear();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It is not needed.

goto exit;
}
}

if (PyUnicode_CheckExact(val)) {
PyObject* trailing = PyUnicode_FromString(". Did you forget 'self' in the method definition?");
if (trailing == NULL) {
PyErr_Clear();
goto exit;
}
PyObject* new_val = PyUnicode_Concat(val, trailing);
if (new_val == NULL) {
PyErr_Clear();
goto exit;
}
Py_DECREF(val);
val = new_val;
PyObject* new_val = PyUnicode_FromFormat("%U. Did you forget 'self' in the method"
" definition?", val);
if (new_val == NULL) {
PyErr_Clear();
goto exit;
}
Py_DECREF(val);
val = new_val;
exit:
PyErr_Restore(type, val, tb);
}

Back | FazBrowse Home | New Git URL