mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
bpo-38530: Include builtins in NameError suggestions (GH-25460)
This commit is contained in:
parent
7f1305ef9e
commit
3ab4bea5a3
2 changed files with 31 additions and 5 deletions
|
@ -4,7 +4,7 @@
|
|||
#include "pycore_pyerrors.h"
|
||||
|
||||
#define MAX_DISTANCE 3
|
||||
#define MAX_CANDIDATE_ITEMS 100
|
||||
#define MAX_CANDIDATE_ITEMS 160
|
||||
#define MAX_STRING_SIZE 25
|
||||
|
||||
/* Calculate the Levenshtein distance between string1 and string2 */
|
||||
|
@ -171,6 +171,16 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc) {
|
|||
}
|
||||
suggestions = calculate_suggestions(dir, name);
|
||||
Py_DECREF(dir);
|
||||
if (suggestions != NULL) {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
dir = PySequence_List(frame->f_builtins);
|
||||
if (dir == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
suggestions = calculate_suggestions(dir, name);
|
||||
Py_DECREF(dir);
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue