summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_capi.py
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2022-02-02 15:57:51 (GMT)
committerGitHub <noreply@github.com>2022-02-02 15:57:51 (GMT)
commit0ef08530124c5ca13a9394f4ac18bee8e6c66409 (patch)
treeddb496b55243ef3f207bb6fdc744fe84d517196e /Lib/test/test_capi.py
parent0d05da1fbf39f32d2c22a1f3702f40f916997b60 (diff)
downloadcpython-0ef08530124c5ca13a9394f4ac18bee8e6c66409.zip
cpython-0ef08530124c5ca13a9394f4ac18bee8e6c66409.tar.gz
cpython-0ef08530124c5ca13a9394f4ac18bee8e6c66409.tar.bz2
bpo-46433: _PyType_GetModuleByDef: handle static types in MRO (GH-30696)
Automerge-Triggered-By: GH:encukou
Diffstat (limited to 'Lib/test/test_capi.py')
-rw-r--r--Lib/test/test_capi.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index a5db8a1..ccf8ced 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -1068,6 +1068,22 @@ class Test_ModuleStateAccess(unittest.TestCase):
with self.assertRaises(TypeError):
increment_count(1, 2, 3)
+ def test_get_module_bad_def(self):
+ # _PyType_GetModuleByDef fails gracefully if it doesn't
+ # find what it's looking for.
+ # see bpo-46433
+ instance = self.module.StateAccessType()
+ with self.assertRaises(TypeError):
+ instance.getmodulebydef_bad_def()
+
+ def test_get_module_static_in_mro(self):
+ # Here, the class _PyType_GetModuleByDef is looking for
+ # appears in the MRO after a static type (Exception).
+ # see bpo-46433
+ class Subclass(BaseException, self.module.StateAccessType):
+ pass
+ self.assertIs(Subclass().get_defining_module(), self.module)
+
if __name__ == "__main__":
unittest.main()