File tree 2 files changed +28
-23
lines changed
Misc/NEWS.d/next/Core and Builtins 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 = {
1746
1746
};
1747
1747
1748
1748
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
+ };
1750
1772
1751
1773
1752
1774
static struct PyModuleDef operatormodule = {
1753
1775
PyModuleDef_HEAD_INIT ,
1754
1776
"_operator" ,
1755
1777
operator_doc ,
1756
- -1 ,
1778
+ 0 ,
1757
1779
operator_methods ,
1758
- NULL ,
1780
+ operator_slots ,
1759
1781
NULL ,
1760
1782
NULL ,
1761
1783
NULL
@@ -1764,24 +1786,5 @@ static struct PyModuleDef operatormodule = {
1764
1786
PyMODINIT_FUNC
1765
1787
PyInit__operator (void )
1766
1788
{
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 );
1787
1790
}
You can’t perform that action at this time.
0 commit comments