From 63caf9b2835d80191dbe4aff7a6924b393e48ecd Mon Sep 17 00:00:00 2001 From: Eldar Abusalimov Date: Sat, 25 Oct 2014 22:17:35 +0400 Subject: [PATCH 11/15] (test) (behavior) error on extending an incomplete type Without a special check for base->tp_mro != NULL extending an uninitialized type results in PyErr_BadInternalCall --- Lib/test/test_mro.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Lib/test/test_mro.py b/Lib/test/test_mro.py index 258acb6..732d705 100644 --- a/Lib/test/test_mro.py +++ b/Lib/test/test_mro.py @@ -196,6 +196,24 @@ class MroTest(unittest.TestCase): self.assertEqual(C.__bases__, (B2,)) self.assertEqual(C.__mro__, tuple(type.mro(C))) + def test_incomplete_extend(self): + """ + Extending an unitialized type with type->tp_mro == NULL must + throw a reasonable TypeError exception, instead of failing + with PyErr_BadInternalCall. + """ + class M(DebugHelperMeta): + def mro(cls): + if cls.__mro__ is None and cls.__name__ != 'X': + with self.assertRaises(TypeError): + class X(cls): + pass + + return type.mro(cls) + + class A(metaclass=M): + pass + if __name__ == '__main__': unittest.main() -- 2.1.1