Skip to content

Commit

Permalink
Fix mypyc failing to compile on CPython 3.10.0a6
Browse files Browse the repository at this point in the history
_PyObject_HasAttrId() has been removed in
python/cpython#22629
  • Loading branch information
freundTech committed Mar 11, 2021
1 parent a503132 commit 2ecdbb1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 13 additions & 2 deletions mypyc/lib-rt/dict_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,16 @@ int CPyDict_Update(PyObject *dict, PyObject *stuff) {
}

int CPyDict_UpdateFromAny(PyObject *dict, PyObject *stuff) {
PyObject *tmp;

if (PyDict_CheckExact(dict)) {
// Argh this sucks
_Py_IDENTIFIER(keys);
if (PyDict_Check(stuff) || _PyObject_HasAttrId(stuff, &PyId_keys)) {
int hasAttr = PyDict_Check(stuff) || _PyObject_LookupAttrId(stuff, &PyId_keys, &tmp);
if (tmp) {
Py_DECREF(tmp);
}
if (hasAttr) {
return PyDict_Update(dict, stuff);
} else {
return PyDict_MergeFromSeq2(dict, stuff, 1);
Expand All @@ -126,6 +132,8 @@ int CPyDict_UpdateFromAny(PyObject *dict, PyObject *stuff) {
}

PyObject *CPyDict_FromAny(PyObject *obj) {
PyObject *tmp;

if (PyDict_Check(obj)) {
return PyDict_Copy(obj);
} else {
Expand All @@ -135,11 +143,14 @@ PyObject *CPyDict_FromAny(PyObject *obj) {
return NULL;
}
_Py_IDENTIFIER(keys);
if (_PyObject_HasAttrId(obj, &PyId_keys)) {
if (_PyObject_LookupAttrId(obj, &PyId_keys, &tmp)) {
res = PyDict_Update(dict, obj);
} else {
res = PyDict_MergeFromSeq2(dict, obj, 1);
}
if (tmp) {
Py_DECREF(tmp);
}
if (res < 0) {
Py_DECREF(dict);
return NULL;
Expand Down
5 changes: 4 additions & 1 deletion mypyc/test-data/run-misc.test
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2ecdbb1

Please sign in to comment.