@@ -164,51 +164,48 @@ calculate_suggestions(PyObject* dir,
164
164
}
165
165
166
166
int
167
- _Py_offer_suggestions (PyAttributeErrorObject * exc ) {
167
+ _Py_offer_suggestions_for_attribute_error (PyAttributeErrorObject * exc ) {
168
168
int return_val = 0 ;
169
169
170
170
PyObject * name = exc -> name ;
171
171
PyObject * v = exc -> obj ;
172
172
173
+ // Aboirt if we don't have an attribute name or we have an invalid one
173
174
if ((name == NULL ) || (v == NULL ) || !PyUnicode_CheckExact (name )) {
174
- return 0 ;
175
+ return -1 ;
175
176
}
176
177
177
178
PyObject * oldexceptionvalue = NULL ;
178
179
Py_ssize_t nargs = PyTuple_GET_SIZE (exc -> args );
179
-
180
- if ( nargs > 1 ) {
181
- // Exceptions with more than 1 value in args are not
182
- // formatted using args, so no need to make a new suggestion.
183
- return 0 ;
184
- }
185
-
186
- if ( nargs == 1 ) {
187
- oldexceptionvalue = PyTuple_GET_ITEM ( exc -> args , 0 );
188
- Py_INCREF ( oldexceptionvalue ) ;
189
- }
190
-
191
- // Check that the the message is an uncode objects that we can use,
192
- // and if not, create an empty value.
193
- if (! oldexceptionvalue || ! PyUnicode_CheckExact ( oldexceptionvalue )) {
194
- Py_XDECREF ( oldexceptionvalue );
195
- oldexceptionvalue = PyUnicode_New ( 0 , 0 ) ;
180
+ switch ( nargs ) {
181
+ case 0 :
182
+ oldexceptionvalue = PyUnicode_New ( 0 , 0 );
183
+ break ;
184
+ case 1 :
185
+ oldexceptionvalue = PyTuple_GET_ITEM ( exc -> args , 0 );
186
+ Py_INCREF ( oldexceptionvalue );
187
+ // Check that the the message is an uncode objects that we can use.
188
+ if (! PyUnicode_CheckExact ( oldexceptionvalue )) {
189
+ return_val = -1 ;
190
+ goto exit ;
191
+ }
192
+ break ;
193
+ default :
194
+ // Exceptions with more than 1 value in args are not
195
+ // formatted using args, so no need to make a new suggestion.
196
+ return 0 ;
196
197
}
197
198
198
- if ( Py_EnterRecursiveCall ( " while getting the __dir__ of an object" )) {
199
- return_val = -1 ;
199
+ PyObject * dir = PyObject_Dir ( v );
200
+ if (! dir ) {
200
201
goto exit ;
201
202
}
202
- PyObject * dir = PyObject_Dir (v );
203
- Py_LeaveRecursiveCall ();
204
203
205
- PyObject * newexceptionvalue = NULL ;
206
- if (dir ) {
207
- newexceptionvalue = calculate_suggestions (dir , name , oldexceptionvalue );
208
- Py_DECREF (dir );
209
- }
204
+ PyObject * newexceptionvalue = calculate_suggestions (dir , name , oldexceptionvalue );
205
+ Py_DECREF (dir );
210
206
211
207
if (newexceptionvalue == NULL ) {
208
+ // We did't find a suggestion :(
212
209
goto exit ;
213
210
}
214
211
0 commit comments