Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[3.11] gh-106030: Miscellaneous fixes in Python/suggestions.c (GH-106… #106039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 12 Python/suggestions.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ calculate_suggestions(PyObject *dir,

for (int i = 0; i < dir_size; ++i) {
PyObject *item = PyList_GET_ITEM(dir, i);
if (_PyUnicode_Equal(name, item)) {
continue;
}
Py_ssize_t item_size;
const char *item_str = PyUnicode_AsUTF8AndSize(item, &item_size);
if (item_str == NULL) {
return NULL;
}
if (PyUnicode_CompareWithASCIIString(name, item_str) == 0) {
continue;
}
// No more than 1/3 of the involved characters should need changed.
Py_ssize_t max_distance = (name_size + item_size + 3) * MOVE_COST / 6;
// Don't take matches we've already beaten.
Expand Down Expand Up @@ -225,19 +225,19 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc)
PyCodeObject *code = PyFrame_GetCode(frame);
assert(code != NULL && code->co_localsplusnames != NULL);
PyObject *varnames = _PyCode_GetVarnames(code);
Py_DECREF(code);
if (varnames == NULL) {
return NULL;
}
PyObject *dir = PySequence_List(varnames);
Py_DECREF(varnames);
Py_DECREF(code);
if (dir == NULL) {
return NULL;
}

PyObject *suggestions = calculate_suggestions(dir, name);
Py_DECREF(dir);
if (suggestions != NULL) {
if (suggestions != NULL|| PyErr_Occurred()) {
return suggestions;
}

Expand All @@ -247,7 +247,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc)
}
suggestions = calculate_suggestions(dir, name);
Py_DECREF(dir);
if (suggestions != NULL) {
if (suggestions != NULL || PyErr_Occurred()) {
return suggestions;
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.