Description
CameraType
EventType
FontType
JoystickType
MaskType
SoundType
ChannelType
RectType
FRectType
(what?)SurfaceType
These *Type
s 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?