Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate and remove the legacy types like SoundType #3239

Open
yunline opened this issue Nov 25, 2024 · 2 comments
Open

Deprecate and remove the legacy types like SoundType #3239

yunline opened this issue Nov 25, 2024 · 2 comments

Comments

@yunline
Copy link
Contributor

yunline commented Nov 25, 2024

  • CameraType
  • EventType
  • FontType
  • JoystickType
  • MaskType
  • SoundType
  • ChannelType
  • RectType
  • FRectType (what?)
  • SurfaceType

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
Copy link
Member

damusss commented Nov 25, 2024

yes

@Starbuck5 Starbuck5 added this to the 3.0.0 milestone Nov 27, 2024
@Starbuck5
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants