Skip to content

Commit c432df6

Browse files
gh-111696, PEP 737: Add PyType_GetModuleName() function (#116824)
Co-authored-by: Eric Snow <[email protected]>
1 parent 25cd873 commit c432df6

File tree

15 files changed

+48
-27
lines changed

15 files changed

+48
-27
lines changed

Doc/c-api/type.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ Type Objects
193193
194194
.. versionadded:: 3.13
195195
196+
.. c:function:: PyObject* PyType_GetModuleName(PyTypeObject *type)
197+
198+
Return the type's module name. Equivalent to getting the ``type.__module__``
199+
attribute.
200+
201+
.. versionadded:: 3.13
202+
196203
.. c:function:: void* PyType_GetSlot(PyTypeObject *type, int slot)
197204
198205
Return the function pointer stored in the given slot. If the

Doc/data/stable_abi.dat

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/whatsnew/3.13.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,10 @@ New Features
16641664
to ``"builtins"``.
16651665
(Contributed by Victor Stinner in :gh:`111696`.)
16661666

1667+
* Add :c:func:`PyType_GetModuleName` function to get the type's module name.
1668+
Equivalent to getting the ``type.__module__`` attribute.
1669+
(Contributed by Eric Snow and Victor Stinner in :gh:`111696`.)
1670+
16671671

16681672
Porting to Python 3.13
16691673
----------------------

Include/internal/pycore_typeobject.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ PyAPI_FUNC(PyObject*) _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj,
151151
PyObject *name, int *meth_found);
152152

153153

154-
// This is exported for the _testinternalcapi module.
155-
PyAPI_FUNC(PyObject *) _PyType_GetModuleName(PyTypeObject *);
156-
157-
158154
#ifdef __cplusplus
159155
}
160156
#endif

Include/object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ PyAPI_FUNC(PyObject *) PyType_GetName(PyTypeObject *);
523523
PyAPI_FUNC(PyObject *) PyType_GetQualName(PyTypeObject *);
524524
#endif
525525
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030D0000
526-
PyAPI_FUNC(PyObject *) PyType_GetFullyQualifiedName(PyTypeObject *);
526+
PyAPI_FUNC(PyObject *) PyType_GetFullyQualifiedName(PyTypeObject *type);
527+
PyAPI_FUNC(PyObject *) PyType_GetModuleName(PyTypeObject *type);
527528
#endif
528529
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000
529530
PyAPI_FUNC(PyObject *) PyType_FromMetaclass(PyTypeObject*, PyObject*, PyType_Spec*, PyObject*);

Lib/test/test_capi/test_misc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,9 @@ def test_get_type_name(self):
11041104
class MyType:
11051105
pass
11061106

1107-
from _testcapi import get_type_name, get_type_qualname, get_type_fullyqualname
1108-
from _testinternalcapi import get_type_module_name
1107+
from _testcapi import (
1108+
get_type_name, get_type_qualname,
1109+
get_type_fullyqualname, get_type_module_name)
11091110

11101111
from collections import OrderedDict
11111112
ht = _testcapi.get_heaptype_for_name()

Lib/test/test_stable_abi_ctypes.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add :c:func:`PyType_GetModuleName` function to get the type's module name.
2+
Equivalent to getting the ``type.__module__`` attribute. Patch by Eric Snow
3+
and Victor Stinner.

Misc/stable_abi.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,3 +2498,5 @@
24982498
# "abi-only" since 3.10. (Same story as PyCFunctionFast.)
24992499
[function.PyType_GetFullyQualifiedName]
25002500
added = '3.13'
2501+
[function.PyType_GetModuleName]
2502+
added = '3.13'

Modules/_functoolsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ partial_repr(partialobject *pto)
402402
goto done;
403403
}
404404

405-
mod = _PyType_GetModuleName(Py_TYPE(pto));
405+
mod = PyType_GetModuleName(Py_TYPE(pto));
406406
if (mod == NULL) {
407407
goto error;
408408
}

0 commit comments

Comments
 (0)