Skip to content

Commit 94ff629

Browse files
committed
Add tests on invalid module/attribute name types
1 parent d2d9246 commit 94ff629

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Lib/test/test_capi/test_import.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ def test_getmoduleattr(self):
327327
getmoduleattr = _testcapi.PyImport_GetModuleAttr
328328
self.check_getmoduleattr(getmoduleattr)
329329

330+
# Invalid module name type
331+
for mod_name in (object(), 123, b'bytes'):
332+
with self.subTest(mod_name=mod_name):
333+
with self.assertRaises(TypeError):
334+
getmoduleattr(mod_name, "attr")
335+
336+
# Invalid attribute name type
337+
for attr_name in (object(), 123, b'bytes'):
338+
with self.subTest(attr_name=attr_name):
339+
with self.assertRaises(TypeError):
340+
getmoduleattr("sys", attr_name)
341+
330342
with self.assertRaises(SystemError):
331343
getmoduleattr(NULL, "argv")
332344
# CRASHES getmoduleattr("sys", NULL)

0 commit comments

Comments
 (0)