bpo-46433: _PyType_GetModuleByDef: handle static types in MRO (GH-30696)

Automerge-Triggered-By: GH:encukou
This commit is contained in:
Petr Viktorin 2022-02-02 16:57:51 +01:00 committed by GitHub
parent 0d05da1fbf
commit 0ef0853012
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 9 deletions

View file

@ -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()