gh-76785: Add _PyType_GetModuleName() to the Internal C-API (gh-112323)

The new function corresponds to the existing (public) PyType_GetName() and PyType_GetQualName().
This commit is contained in:
Eric Snow 2023-11-22 15:03:33 -07:00 committed by GitHub
parent 5c3a129ecf
commit 790db85c77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 0 deletions

View file

@ -1098,6 +1098,21 @@ class CAPITest(unittest.TestCase):
del d.extra
self.assertIsNone(d.extra)
def test_get_type_module_name(self):
from collections import OrderedDict
ht = _testcapi.get_heaptype_for_name()
for cls, expected in {
int: 'builtins',
OrderedDict: 'collections',
ht: '_testcapi',
}.items():
with self.subTest(repr(cls)):
modname = _testinternalcapi.get_type_module_name(cls)
self.assertEqual(modname, expected)
ht.__module__ = 'test_module'
modname = _testinternalcapi.get_type_module_name(ht)
self.assertEqual(modname, 'test_module')
@requires_limited_api
class TestHeapTypeRelative(unittest.TestCase):