[pypy-svn] r11031 - pypy/dist/pypy/objspace/std

pedronis at codespeak.net pedronis at codespeak.net
Fri Apr 22 18:11:17 CEST 2005


Author: pedronis
Date: Fri Apr 22 18:11:16 2005
New Revision: 11031

Modified:
   pypy/dist/pypy/objspace/std/objecttype.py
   pypy/dist/pypy/objspace/std/objspace.py
   pypy/dist/pypy/objspace/std/typeobject.py
   pypy/dist/pypy/objspace/std/typetype.py
Log:
we are really using the specific methods on by W_TypeObject instances, also we don't plan right now for multiple
impl for types: more precise and annotator friendlier typechecking



Modified: pypy/dist/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objecttype.py	(original)
+++ pypy/dist/pypy/objspace/std/objecttype.py	Fri Apr 22 18:11:16 2005
@@ -21,8 +21,10 @@
 
 def descr__new__(space, w_type, __args__):
     from pypy.objspace.std.objectobject import W_ObjectObject
+    from pypy.objspace.std.typetype import _precheck_for_new
     # don't allow arguments if the default object.__init__() is about
     # to be called
+    w_type = _precheck_for_new(space, w_type)
     w_parentinit, w_ignored = w_type.lookup_where('__init__')
     if w_parentinit is space.w_object:
         try:

Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Fri Apr 22 18:11:16 2005
@@ -275,7 +275,7 @@
         if self.is_true(self.is_(w_type, w_subtype)):
             instance =  instantiate(cls)
         else:
-            w_type.check_user_subclass(w_subtype)
+            w_subtype = w_type.check_user_subclass(w_subtype)
             subcls = get_unique_interplevel_subclass(cls, w_subtype.hasdict, w_subtype.nslots != 0)
             instance = instantiate(subcls)
             instance.user_setup(self, w_subtype, w_subtype.nslots)

Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Fri Apr 22 18:11:16 2005
@@ -49,7 +49,7 @@
             # find the most specific typedef
             instancetypedef = object_typedef
             for w_base in bases_w:
-                if not space.is_true(space.isinstance(w_base, space.w_type)):
+                if not isinstance(w_base, W_TypeObject):
                     continue
                 if issubtypedef(w_base.instancetypedef, instancetypedef):
                     if instancetypedef is not w_base.instancetypedef:
@@ -69,7 +69,7 @@
             hasoldstylebase = False
             w_most_derived_base_with_slots = None
             for w_base in bases_w:
-                if not space.is_true(space.isinstance(w_base, space.w_type)):
+                if not isinstance(w_base, W_TypeObject):
                     hasoldstylebase = True
                     continue
                 if w_base.nslots != 0:
@@ -177,7 +177,7 @@
 
     def check_user_subclass(w_self, w_subtype):
         space = w_self.space
-        if not space.is_true(space.isinstance(w_subtype, space.w_type)):
+        if not isinstance(w_subtype, W_TypeObject):
             raise OperationError(space.w_TypeError,
                 space.wrap("X is not a type object (%s)" % (
                     space.type(w_subtype).name)))
@@ -189,6 +189,7 @@
             raise OperationError(space.w_TypeError,
                 space.wrap("%s.__new__(%s) is not safe, use %s.__new__()" % (
                     w_self.name, w_subtype.name, w_subtype.name)))
+        return w_subtype
 
     def getdict(w_self):
         # XXX should return a <dictproxy object>

Modified: pypy/dist/pypy/objspace/std/typetype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typetype.py	(original)
+++ pypy/dist/pypy/objspace/std/typetype.py	Fri Apr 22 18:11:16 2005
@@ -7,7 +7,10 @@
 def descr__new__(space, w_typetype, w_name, w_bases, w_dict):
     "This is used to create user-defined classes only."
     from pypy.objspace.std.typeobject import W_TypeObject
-    # XXX check types 
+    # XXX check types
+
+    w_typetype = _precheck_for_new(space, w_typetype)
+    
     bases_w = space.unpackiterable(w_bases)
 
     w_winner = w_typetype
@@ -43,6 +46,13 @@
     w_type.__init__(space, name, bases_w or [space.w_object], dict_w)
     return w_type
 
+def _precheck_for_new(space, w_type):
+    from pypy.objspace.std.typeobject import W_TypeObject
+    if not isinstance(w_type, W_TypeObject):
+        raise OperationError(space.w_TypeError,
+                             space.wrap("X is not a type object (%s)" % (space.type(w_type).name)))
+    return w_type
+
 def _check(space, w_type, msg=None):
     from pypy.objspace.std.typeobject import W_TypeObject
     if not isinstance(w_type, W_TypeObject):
@@ -90,6 +100,7 @@
         return space.get(w_result, space.w_None, w_type)
 
 def descr__flags(space, w_type):
+    w_type = _check(space, w_type)    
     return space.wrap(w_type.__flags__)
 
 def defunct_descr_get__module(space, w_type):
@@ -105,12 +116,14 @@
 # therefore, we use the module attribute whenever it exists.
 
 def descr_get__module(space, w_type):
+    w_type = _check(space, w_type)    
     if '__module__' in w_type.dict_w:
         return w_type.dict_w['__module__']
     else:
         return space.wrap('__builtin__')
 
 def descr_set__module(space, w_type, w_value):
+    w_type = _check(space, w_type)    
     if not (w_type.__flags__ & _HEAPTYPE):
         raise OperationError(space.w_TypeError, 
                              space.wrap("can't set %s.__module__" %



More information about the Pypy-commit mailing list