From: Guido van Rossum Date: Fri, 14 Dec 2001 04:19:56 +0000 (+0000) Subject: (Merge into trunk.) X-Git-Tag: v2.2.1c1~370 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e54616cb6fdd9f9fb0d86ddd2cd5c4ffb51771b8;p=python (Merge into trunk.) Fix for SF bug #492345. (I could've sworn I checked this in, but apparently I didn't!) This code: class Classic: pass class New(Classic): __metaclass__ = type attempts to create a new-style class with only classic bases -- but it doesn't work right. Attempts to fix it so it works caused problems elsewhere, so I'm now raising a TypeError in this case. --- diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 1ec7c19c80..ea987f223c 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -922,6 +922,16 @@ def multi(): vereq(m.m3method(), "M3 a") vereq(m.all_method(), "M3 b") + class Classic: + pass + try: + class New(Classic): + __metaclass__ = type + except TypeError: + pass + else: + raise TestFailed, "new class with only classic bases - shouldn't be" + def diamond(): if verbose: print "Testing multiple inheritance special cases..." class A(object): diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 6243e81e71..ba3006389f 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -757,7 +757,9 @@ best_base(PyObject *bases) return NULL; } } - assert(base != NULL); + if (base == NULL) + PyErr_SetString(PyExc_TypeError, + "a new-style class can't have only classic bases"); return base; }