mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
bpo-29727: Register array.array as a MutableSequence (GH-21338)
This commit is contained in:
parent
b3dd5cd4a3
commit
e51dd9dad6
3 changed files with 88 additions and 0 deletions
|
@ -2989,6 +2989,26 @@ array_modexec(PyObject *m)
|
|||
Py_DECREF((PyObject *)&Arraytype);
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyObject *abc_mod = PyImport_ImportModule("collections.abc");
|
||||
if (!abc_mod) {
|
||||
Py_DECREF((PyObject *)&Arraytype);
|
||||
return -1;
|
||||
}
|
||||
PyObject *mutablesequence = PyObject_GetAttrString(abc_mod, "MutableSequence");
|
||||
Py_DECREF(abc_mod);
|
||||
if (!mutablesequence) {
|
||||
Py_DECREF((PyObject *)&Arraytype);
|
||||
return -1;
|
||||
}
|
||||
PyObject *res = PyObject_CallMethod(mutablesequence, "register", "O", (PyObject *)&Arraytype);
|
||||
Py_DECREF(mutablesequence);
|
||||
if (!res) {
|
||||
Py_DECREF((PyObject *)&Arraytype);
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(res);
|
||||
|
||||
Py_INCREF((PyObject *)&Arraytype);
|
||||
if (PyModule_AddObject(m, "array", (PyObject *)&Arraytype) < 0) {
|
||||
Py_DECREF((PyObject *)&Arraytype);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue