[pypy-svn] r12321 - in pypy/dist/pypy/objspace/std: . test

pedronis at codespeak.net pedronis at codespeak.net
Sun May 15 20:33:52 CEST 2005


Author: pedronis
Date: Sun May 15 20:33:52 2005
New Revision: 12321

Modified:
   pypy/dist/pypy/objspace/std/test/test_typeobject.py
   pypy/dist/pypy/objspace/std/typeobject.py
Log:
raise an error if trying to create an new-style class with only old style bases



Modified: pypy/dist/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_typeobject.py	Sun May 15 20:33:52 2005
@@ -338,3 +338,8 @@
             __metaclass__ = T
         assert d == ['miss']
         assert C.x() == 1
+
+    def test_only_classic_bases_fails(self):
+        class C:
+            __metaclass__ = _classobj
+        raises(TypeError, type, 'D', (C,), {})

Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Sun May 15 20:33:52 2005
@@ -92,10 +92,12 @@
             w_self.hasdict = False
             hasoldstylebase = False
             w_most_derived_base_with_slots = None
+            newstyle = False
             for w_base in bases_w:
                 if not isinstance(w_base, W_TypeObject):
                     hasoldstylebase = True
                     continue
+                newstyle = True
                 if w_base.nslots != 0:
                     if w_most_derived_base_with_slots is None:
                         w_most_derived_base_with_slots = w_base
@@ -107,6 +109,10 @@
                                                  space.wrap("instance layout conflicts in "
                                                             "multiple inheritance"))
                 w_self.hasdict = w_self.hasdict or w_base.hasdict
+            if not newstyle: # only classic bases
+                raise OperationError(space.w_TypeError,
+                                     space.wrap("a new-style class can't have only classic bases"))
+
             if w_most_derived_base_with_slots:
                 nslots = w_most_derived_base_with_slots.nslots
                 w_self.w_bestbase = w_most_derived_base_with_slots



More information about the Pypy-commit mailing list