Skip to content

Commit 6289b78

Browse files
committed
More cosmetic changes
1 parent a27a0fd commit 6289b78

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

Python/suggestions.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,37 +130,37 @@ calculate_suggestions(PyObject* dir,
130130
PyObject* name,
131131
PyObject* oldexceptionvalue)
132132
{
133-
if (!PyList_CheckExact(dir)) {
134-
return NULL;
135-
}
133+
assert(PyList_CheckExact(dir));
134+
136135
Py_ssize_t dir_size = PyList_GET_SIZE(dir);
136+
if (dir_size >= MAX_GETATTR_PREDICT_ITEMS) {
137+
return NULL;
138+
}
139+
140+
int suggestion_distance = PyUnicode_GetLength(name);
137141
PyObject* suggestion = NULL;
138-
if (dir_size <= MAX_GETATTR_PREDICT_ITEMS) {
139-
int suggestion_distance = PyUnicode_GetLength(name);
140-
for (int i = 0; i < dir_size; ++i) {
141-
PyObject *item = PyList_GET_ITEM(dir, i);
142-
const char *name_str = PyUnicode_AsUTF8(name);
143-
if (name_str == NULL) {
144-
PyErr_Clear();
145-
continue;
146-
}
147-
int current_distance = distance(PyUnicode_AsUTF8(name),
148-
PyUnicode_AsUTF8(item));
149-
if (current_distance > MAX_GETATTR_PREDICT_DIST){
150-
continue;
151-
}
152-
if (!suggestion || current_distance < suggestion_distance) {
153-
suggestion = item;
154-
suggestion_distance = current_distance;
155-
}
142+
for (int i = 0; i < dir_size; ++i) {
143+
PyObject *item = PyList_GET_ITEM(dir, i);
144+
const char *name_str = PyUnicode_AsUTF8(name);
145+
if (name_str == NULL) {
146+
PyErr_Clear();
147+
continue;
148+
}
149+
int current_distance = distance(PyUnicode_AsUTF8(name),
150+
PyUnicode_AsUTF8(item));
151+
if (current_distance > MAX_GETATTR_PREDICT_DIST){
152+
continue;
156153
}
154+
if (!suggestion || current_distance < suggestion_distance) {
155+
suggestion = item;
156+
suggestion_distance = current_distance;
157+
}
157158
}
158159
if (!suggestion) {
159160
return NULL;
160161
}
161162
return PyUnicode_FromFormat("%S\n\nDid you mean: %U?",
162-
oldexceptionvalue,
163-
suggestion);
163+
oldexceptionvalue, suggestion);
164164
}
165165

166166
int

0 commit comments

Comments
 (0)