diff --git a/mypyc/lib-rt/dict_ops.c b/mypyc/lib-rt/dict_ops.c index 1e635ada2c00..4f831d0ba850 100644 --- a/mypyc/lib-rt/dict_ops.c +++ b/mypyc/lib-rt/dict_ops.c @@ -115,7 +115,7 @@ int CPyDict_UpdateFromAny(PyObject *dict, PyObject *stuff) { if (PyDict_CheckExact(dict)) { // Argh this sucks _Py_IDENTIFIER(keys); - if (PyDict_Check(stuff) || _PyObject_HasAttrId(stuff, &PyId_keys)) { + if (PyDict_Check(stuff) || _CPyObject_HasAttrId(stuff, &PyId_keys)) { return PyDict_Update(dict, stuff); } else { return PyDict_MergeFromSeq2(dict, stuff, 1); @@ -135,7 +135,7 @@ PyObject *CPyDict_FromAny(PyObject *obj) { return NULL; } _Py_IDENTIFIER(keys); - if (_PyObject_HasAttrId(obj, &PyId_keys)) { + if (_CPyObject_HasAttrId(obj, &PyId_keys)) { res = PyDict_Update(dict, obj); } else { res = PyDict_MergeFromSeq2(dict, obj, 1); diff --git a/mypyc/lib-rt/pythonsupport.h b/mypyc/lib-rt/pythonsupport.h index 864a1d152aa0..a8b00e168bb7 100644 --- a/mypyc/lib-rt/pythonsupport.h +++ b/mypyc/lib-rt/pythonsupport.h @@ -389,4 +389,18 @@ _CPyDictView_New(PyObject *dict, PyTypeObject *type) } #endif +#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >=10 +static int +_CPyObject_HasAttrId(PyObject *v, _Py_Identifier *name) { + PyObject *tmp = NULL; + int result = _PyObject_LookupAttrId(v, name, &tmp); + if (tmp) { + Py_DECREF(tmp); + } + return result; +} +#else +#define _CPyObject_HasAttrId _PyObject_HasAttrId +#endif + #endif diff --git a/mypyc/test-data/run-misc.test b/mypyc/test-data/run-misc.test index cc9ef444f31b..8b79949b55ad 100644 --- a/mypyc/test-data/run-misc.test +++ b/mypyc/test-data/run-misc.test @@ -940,7 +940,10 @@ import sys # We lie about the version we are running in tests if it is 3.5, so # that hits a crash case. -if sys.version_info[:2] == (3, 9): +if sys.version_info[:2] == (3, 10): + def version() -> int: + return 10 +elif sys.version_info[:2] == (3, 9): def version() -> int: return 9 elif sys.version_info[:2] == (3, 8):