@@ -130,37 +130,37 @@ calculate_suggestions(PyObject* dir,
130
130
PyObject * name ,
131
131
PyObject * oldexceptionvalue )
132
132
{
133
- if (!PyList_CheckExact (dir )) {
134
- return NULL ;
135
- }
133
+ assert (PyList_CheckExact (dir ));
134
+
136
135
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 );
137
141
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 ;
156
153
}
154
+ if (!suggestion || current_distance < suggestion_distance ) {
155
+ suggestion = item ;
156
+ suggestion_distance = current_distance ;
157
+ }
157
158
}
158
159
if (!suggestion ) {
159
160
return NULL ;
160
161
}
161
162
return PyUnicode_FromFormat ("%S\n\nDid you mean: %U?" ,
162
- oldexceptionvalue ,
163
- suggestion );
163
+ oldexceptionvalue , suggestion );
164
164
}
165
165
166
166
int
0 commit comments