gh-111696, PEP 737: Add PyType_GetModuleName() function (#116824)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
This commit is contained in:
Victor Stinner 2024-03-14 19:17:43 +01:00 committed by GitHub
parent 25cd8730aa
commit c432df6d56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 48 additions and 27 deletions

View file

@ -402,7 +402,7 @@ partial_repr(partialobject *pto)
goto done;
}
mod = _PyType_GetModuleName(Py_TYPE(pto));
mod = PyType_GetModuleName(Py_TYPE(pto));
if (mod == NULL) {
goto error;
}

View file

@ -622,6 +622,14 @@ get_type_fullyqualname(PyObject *self, PyObject *type)
}
static PyObject *
get_type_module_name(PyObject *self, PyObject *type)
{
assert(PyType_Check(type));
return PyType_GetModuleName((PyTypeObject *)type);
}
static PyObject *
test_get_type_dict(PyObject *self, PyObject *Py_UNUSED(ignored))
{
@ -3268,6 +3276,7 @@ static PyMethodDef TestMethods[] = {
{"get_type_name", get_type_name, METH_O},
{"get_type_qualname", get_type_qualname, METH_O},
{"get_type_fullyqualname", get_type_fullyqualname, METH_O},
{"get_type_module_name", get_type_module_name, METH_O},
{"test_get_type_dict", test_get_type_dict, METH_NOARGS},
{"_test_thread_state", test_thread_state, METH_VARARGS},
#ifndef MS_WINDOWS

View file

@ -28,7 +28,6 @@
#include "pycore_pathconfig.h" // _PyPathConfig_ClearGlobal()
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_typeobject.h" // _PyType_GetModuleName()
#include "interpreteridobject.h" // PyInterpreterID_LookUp()
@ -1631,13 +1630,6 @@ perf_trampoline_set_persist_after_fork(PyObject *self, PyObject *args)
}
static PyObject *
get_type_module_name(PyObject *self, PyObject *type)
{
assert(PyType_Check(type));
return _PyType_GetModuleName((PyTypeObject *)type);
}
static PyObject *
get_rare_event_counters(PyObject *self, PyObject *type)
{
@ -1741,7 +1733,6 @@ static PyMethodDef module_functions[] = {
{"get_crossinterp_data", get_crossinterp_data, METH_VARARGS},
{"restore_crossinterp_data", restore_crossinterp_data, METH_VARARGS},
_TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF
{"get_type_module_name", get_type_module_name, METH_O},
{"get_rare_event_counters", get_rare_event_counters, METH_NOARGS},
{"reset_rare_event_counters", reset_rare_event_counters, METH_NOARGS},
#ifdef Py_GIL_DISABLED