@@ -2343,26 +2343,27 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
2343
2343
}
2344
2344
2345
2345
if (len ) {
2346
+ PyObject * func ;
2346
2347
PyObject * other = PyTuple_GET_ITEM (args , 0 ); /* borrowed reference */
2347
2348
assert (other != NULL );
2348
2349
Py_INCREF (other );
2349
- if PyDict_CheckExact (other ) {
2350
- PyObject * items ;
2351
- if (PyDict_CheckExact (other ))
2352
- items = PyDict_Items (other );
2353
- else
2354
- items = _PyObject_CallMethodId (other , & PyId_items , NULL );
2350
+ if (PyDict_CheckExact (other )) {
2351
+ PyObject * items = PyDict_Items (other );
2355
2352
Py_DECREF (other );
2356
2353
if (items == NULL )
2357
2354
return NULL ;
2358
2355
res = mutablemapping_add_pairs (self , items );
2359
2356
Py_DECREF (items );
2360
2357
if (res == -1 )
2361
2358
return NULL ;
2359
+ goto handle_kwargs ;
2362
2360
}
2363
- else if (_PyObject_HasAttrId (other , & PyId_keys )) { /* never fails */
2361
+
2362
+ func = _PyObject_GetAttrId (other , & PyId_keys );
2363
+ if (func != NULL ) {
2364
2364
PyObject * keys , * iterator , * key ;
2365
- keys = _PyObject_CallMethodIdObjArgs (other , & PyId_keys , NULL );
2365
+ keys = _PyObject_CallNoArg (func );
2366
+ Py_DECREF (func );
2366
2367
if (keys == NULL ) {
2367
2368
Py_DECREF (other );
2368
2369
return NULL ;
@@ -2388,29 +2389,45 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
2388
2389
Py_DECREF (iterator );
2389
2390
if (res != 0 || PyErr_Occurred ())
2390
2391
return NULL ;
2392
+ goto handle_kwargs ;
2393
+ }
2394
+ else if (!PyErr_ExceptionMatches (PyExc_AttributeError )) {
2395
+ Py_DECREF (other );
2396
+ return NULL ;
2397
+ }
2398
+ else {
2399
+ PyErr_Clear ();
2391
2400
}
2392
- else if (_PyObject_HasAttrId (other , & PyId_items )) { /* never fails */
2401
+
2402
+ func = _PyObject_GetAttrId (other , & PyId_items );
2403
+ if (func != NULL ) {
2393
2404
PyObject * items ;
2394
- if (PyDict_CheckExact (other ))
2395
- items = PyDict_Items (other );
2396
- else
2397
- items = _PyObject_CallMethodId (other , & PyId_items , NULL );
2398
2405
Py_DECREF (other );
2406
+ items = _PyObject_CallNoArg (func );
2407
+ Py_DECREF (func );
2399
2408
if (items == NULL )
2400
2409
return NULL ;
2401
2410
res = mutablemapping_add_pairs (self , items );
2402
2411
Py_DECREF (items );
2403
2412
if (res == -1 )
2404
2413
return NULL ;
2414
+ goto handle_kwargs ;
2405
2415
}
2406
- else {
2407
- res = mutablemapping_add_pairs (self , other );
2416
+ else if (!PyErr_ExceptionMatches (PyExc_AttributeError )) {
2408
2417
Py_DECREF (other );
2409
- if (res != 0 )
2410
- return NULL ;
2418
+ return NULL ;
2411
2419
}
2420
+ else {
2421
+ PyErr_Clear ();
2422
+ }
2423
+
2424
+ res = mutablemapping_add_pairs (self , other );
2425
+ Py_DECREF (other );
2426
+ if (res != 0 )
2427
+ return NULL ;
2412
2428
}
2413
2429
2430
+ handle_kwargs :
2414
2431
/* now handle kwargs */
2415
2432
assert (kwargs == NULL || PyDict_Check (kwargs ));
2416
2433
if (kwargs != NULL && PyDict_GET_SIZE (kwargs )) {
0 commit comments