@@ -2240,14 +2240,23 @@ dummy_func(
22402240 PyObject * dict_o = PyStackRef_AsPyObjectBorrow (dict );
22412241 PyObject * update_o = PyStackRef_AsPyObjectBorrow (update );
22422242
2243- int err = PyDict_Update (dict_o , update_o );
2244- if (err < 0 ) {
2245- int matches = _PyErr_ExceptionMatches (tstate , PyExc_AttributeError );
2246- if (matches ) {
2243+ if (!PyAnyDict_Check (update_o )) {
2244+ int has_keys = PyObject_HasAttrWithError (
2245+ update_o , & _Py_ID (keys ));
2246+ if (has_keys < 0 ) {
2247+ PyStackRef_CLOSE (update );
2248+ ERROR_IF (true);
2249+ }
2250+ if (!has_keys ) {
22472251 _PyErr_Format (tstate , PyExc_TypeError ,
22482252 "'%.200s' object is not a mapping" ,
22492253 Py_TYPE (update_o )-> tp_name );
2254+ PyStackRef_CLOSE (update );
2255+ ERROR_IF (true);
22502256 }
2257+ }
2258+ int err = PyDict_Update (dict_o , update_o );
2259+ if (err < 0 ) {
22512260 PyStackRef_CLOSE (update );
22522261 ERROR_IF (true);
22532262 }
@@ -2259,6 +2268,21 @@ dummy_func(
22592268 PyObject * dict_o = PyStackRef_AsPyObjectBorrow (dict );
22602269 PyObject * update_o = PyStackRef_AsPyObjectBorrow (update );
22612270
2271+ if (!PyAnyDict_Check (update_o )) {
2272+ int has_keys = PyObject_HasAttrWithError (
2273+ update_o , & _Py_ID (keys ));
2274+ if (has_keys < 0 ) {
2275+ PyStackRef_CLOSE (update );
2276+ ERROR_IF (true);
2277+ }
2278+ if (!has_keys ) {
2279+ _PyErr_Format (tstate , PyExc_TypeError ,
2280+ "Value after ** must be a mapping, not %.200s" ,
2281+ Py_TYPE (update_o )-> tp_name );
2282+ PyStackRef_CLOSE (update );
2283+ ERROR_IF (true);
2284+ }
2285+ }
22622286 int err = _PyDict_MergeEx (dict_o , update_o , 2 );
22632287 if (err < 0 ) {
22642288 _PyEval_FormatKwargsError (tstate , callable_o , update_o );
0 commit comments