summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-04-17 21:26:54 (GMT)
committerGitHub <noreply@github.com>2021-04-17 21:26:54 (GMT)
commit3ab4bea5a3ac28820781cf62a768c65370c9054c (patch)
tree8c079f4a5d1c1c1616fa84e29d825aa83287997c /Python
parent7f1305ef9ea7234e1a5aacbea17490232e9b7dc2 (diff)
downloadcpython-3ab4bea5a3ac28820781cf62a768c65370c9054c.zip
cpython-3ab4bea5a3ac28820781cf62a768c65370c9054c.tar.gz
cpython-3ab4bea5a3ac28820781cf62a768c65370c9054c.tar.bz2
bpo-38530: Include builtins in NameError suggestions (GH-25460)
Diffstat (limited to 'Python')
-rw-r--r--Python/suggestions.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Python/suggestions.c b/Python/suggestions.c
index e422760..aa4870d 100644
--- a/Python/suggestions.c
+++ b/Python/suggestions.c
@@ -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;
}