File tree Expand file tree Collapse file tree 2 files changed +28
-23
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 2 files changed +28
-23
lines changed Original file line number Diff line number Diff line change 1+ Port operator module to multiphase initialization (PEP 489). Patch by Paulo
2+ Henrique Silva.
Original file line number Diff line number Diff line change @@ -1746,16 +1746,38 @@ static PyTypeObject methodcaller_type = {
17461746};
17471747
17481748
1749- /* Initialization function for the module (*must* be called PyInit__operator) */
1749+ static int
1750+ operator_exec (PyObject * module )
1751+ {
1752+ PyTypeObject * types [] = {
1753+ & itemgetter_type ,
1754+ & attrgetter_type ,
1755+ & methodcaller_type
1756+ };
1757+
1758+ for (size_t i = 0 ; i < Py_ARRAY_LENGTH (types ); i ++ ) {
1759+ if (PyModule_AddType (module , types [i ]) < 0 ) {
1760+ return -1 ;
1761+ }
1762+ }
1763+
1764+ return 0 ;
1765+ }
1766+
1767+
1768+ static struct PyModuleDef_Slot operator_slots [] = {
1769+ {Py_mod_exec , operator_exec },
1770+ {0 , NULL }
1771+ };
17501772
17511773
17521774static struct PyModuleDef operatormodule = {
17531775 PyModuleDef_HEAD_INIT ,
17541776 "_operator" ,
17551777 operator_doc ,
1756- -1 ,
1778+ 0 ,
17571779 operator_methods ,
1758- NULL ,
1780+ operator_slots ,
17591781 NULL ,
17601782 NULL ,
17611783 NULL
@@ -1764,24 +1786,5 @@ static struct PyModuleDef operatormodule = {
17641786PyMODINIT_FUNC
17651787PyInit__operator (void )
17661788{
1767- PyObject * m ;
1768-
1769- /* Create the module and add the functions */
1770- m = PyModule_Create (& operatormodule );
1771- if (m == NULL )
1772- return NULL ;
1773-
1774- PyTypeObject * types [] = {
1775- & itemgetter_type ,
1776- & attrgetter_type ,
1777- & methodcaller_type
1778- };
1779-
1780- for (size_t i = 0 ; i < Py_ARRAY_LENGTH (types ); i ++ ) {
1781- if (PyModule_AddType (m , types [i ]) < 0 ) {
1782- return NULL ;
1783- }
1784- }
1785-
1786- return m ;
1789+ return PyModuleDef_Init (& operatormodule );
17871790}
You can’t perform that action at this time.
0 commit comments