@@ -68,9 +68,7 @@ key_get_repeat(PyObject *self, PyObject *_null)
6868 * https://github.com/pygame-community/pygame-ce/issues/519
6969 * so that they work with SDL_GetKeyboardState().
7070 */
71- #define _PG_SCANCODEWRAPPER_TYPE_NAME "ScancodeWrapper"
72- #define _PG_SCANCODEWRAPPER_TYPE_FULLNAME \
73- "pygame.key." _PG_SCANCODEWRAPPER_TYPE_NAME
71+ #define _PG_SCANCODEWRAPPER_TYPE_FULLNAME "pygame.key.ScancodeWrapper"
7472
7573typedef struct {
7674 PyTupleObject tuple ;
@@ -155,7 +153,7 @@ pg_scancodewrapper_repr(pgScancodeWrapper *self)
155153}
156154
157155static PyTypeObject pgScancodeWrapper_Type = {
158- PyVarObject_HEAD_INIT (NULL , 0 ).tp_name = "pygame.key.ScancodeWrapper" ,
156+ PyVarObject_HEAD_INIT (NULL , 0 ).tp_name = _PG_SCANCODEWRAPPER_TYPE_FULLNAME ,
159157 .tp_repr = (reprfunc )pg_scancodewrapper_repr ,
160158 .tp_as_mapping = & pg_scancodewrapper_mapping ,
161159 .tp_iter = (getiterfunc )pg_iter_raise ,
@@ -655,20 +653,18 @@ MODINIT_DEFINE(key)
655653 if (PyErr_Occurred ()) {
656654 return NULL ;
657655 }
658- /* type preparation */
659- pgScancodeWrapper_Type .tp_base = & PyTuple_Type ;
660- if (PyType_Ready (& pgScancodeWrapper_Type ) < 0 ) {
661- return NULL ;
662- }
663656
664657 /* create the module */
665658 module = PyModule_Create (& _module );
666659 if (module == NULL ) {
667660 return NULL ;
668661 }
669662
670- if (PyModule_AddObjectRef (module , _PG_SCANCODEWRAPPER_TYPE_NAME ,
671- (PyObject * )& pgScancodeWrapper_Type )) {
663+ // has to be set in init function rather than statically per note on
664+ // https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_base
665+ pgScancodeWrapper_Type .tp_base = & PyTuple_Type ;
666+
667+ if (PyModule_AddType (module , & pgScancodeWrapper_Type )) {
672668 Py_DECREF (module );
673669 return NULL ;
674670 }
0 commit comments