Skip to content

Fix mypyc failing to compile on CPython 3.10.0a6 #10202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mypyc/lib-rt/dict_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions mypyc/lib-rt/pythonsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
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