pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
948 stars 158 forks source link

Deprecate and remove the legacy types like `SoundType` #3239

Open yunline opened 5 days ago

yunline commented 5 days ago

These *Types has a long history. You can find them since the first commit of pygame on github. They are aliases of the original type object and are not recommended to use.

What are *Type used for?

Before python 2.3, there is no tp_new slot in PyTypeObject struct. People use a function to "new" a class defined by c extension.

// Copied from https://docs.python.org/2.2/ext/dnt-basics.html
...

static PyMethodDef noddy_methods[] = {
    {"new_noddy", noddy_new_noddy, METH_VARARGS,
     "Create a new Noddy object."},
    {NULL, NULL, 0, NULL}
};

DL_EXPORT(void)
initnoddy(void) 
{
    noddy_NoddyType.ob_type = &PyType_Type;

    Py_InitModule("noddy", noddy_methods);
}

Take Event as an example, at that time, EventType is the type of event, people need to call Event() function, to create an EventType object.

After python2.3, API changed, people no longger need a explicit function to "new" a class

// Copied from https://docs.python.org/2.3/ext/dnt-basics.html
...

static PyMethodDef noddy_methods[] = {
    {NULL}  /* Sentinel */
};

#ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
initnoddy(void) 
{
    PyObject* m;

    noddy_NoddyType.tp_new = PyType_GenericNew;
    if (PyType_Ready(&noddy_NoddyType) < 0)
        return;

    m = Py_InitModule3("noddy", noddy_methods,
                       "Example module that creates an extension type.");

    Py_INCREF(&noddy_NoddyType);
    PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType);
}

Again, take Event as example, now people only need to call EventType() to create an EventType object

To keep the compatibility of the code written before python 2.2, the Event become the type name and EventType become an alias. People can still call Event() to get an Event object.

These could explain why there are so many *Type in pygame.

Deprecate and remove

These aliases are created to keep the compatibility with python 2.2, whose last release is on 30 May 2003. Today is 25 Nov 2024, we are currently dropping python 3.8 and porting modules to SDL3. So, why not?

damusss commented 5 days ago

yes

Starbuck5 commented 3 days ago

I consider these deprecated already, they're not documented or anything. Are you proposing to add deprecation warnings on their use? If so, how? They are not as straightforward to add a warning to as a function.

I think removing them would be good for 3.0