[pypy-svn] r5132 - in pypy/trunk/src/pypy: interpreter objspace/std

arigo at codespeak.net arigo at codespeak.net
Wed Jun 16 19:32:38 CEST 2004


Author: arigo
Date: Wed Jun 16 19:32:37 2004
New Revision: 5132

Modified:
   pypy/trunk/src/pypy/interpreter/pyopcode.py
   pypy/trunk/src/pypy/objspace/std/objecttype.py
   pypy/trunk/src/pypy/objspace/std/typeobject.py
Log:
* raise Type, InstanceOfSubType was broken
* object.__new__() now complains if given arguments unless object.__init__()
  is overridden, as per Python 2.3 behavior


Modified: pypy/trunk/src/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pyopcode.py	(original)
+++ pypy/trunk/src/pypy/interpreter/pyopcode.py	Wed Jun 16 19:32:37 2004
@@ -860,8 +860,8 @@
         etype = etype[0]
     if isinstance(etype, type):
         if isinstance(value, etype):
-            # raise Type, Instance: everything is fine
-            pass
+            # raise Type, Instance: let etype be the exact type of value
+            etype = value.__class__
         elif value is None:
             # raise Type: we assume we have to instantiate Type
             value = etype()

Modified: pypy/trunk/src/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objecttype.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/objecttype.py	Wed Jun 16 19:32:37 2004
@@ -22,14 +22,19 @@
     return space.type(w_obj)
 
 def descr__new__(space, w_type, *args_w, **kwds_w):
-    # XXX 2.2 behavior: ignoring all arguments
     from pypy.objspace.std.objectobject import W_ObjectObject
+    # don't allow arguments if the default object.__init__() is about
+    # to be called
+    w_parentinit, w_ignored = w_type.lookup_where('__init__')
+    if w_parentinit is space.w_object and (args_w or kwds_w):
+        raise OperationError(space.w_TypeError,
+                             space.wrap("default __new__ takes no parameters"))
     w_obj = space.allocate_instance(W_ObjectObject, w_type)
     w_obj.__init__(space)
     return w_obj
 
 def descr__init__(space, *args_w, **kwds_w):
-    pass   # XXX 2.2. behavior: ignoring all arguments
+    pass
 
 # ____________________________________________________________
 

Modified: pypy/trunk/src/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/typeobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/typeobject.py	Wed Jun 16 19:32:37 2004
@@ -41,8 +41,6 @@
 
     def lookup(w_self, key):
         # note that this doesn't call __get__ on the result at all
-        # XXX this should probably also return the (parent) class in which
-        # the attribute was found
         space = w_self.space
         for w_class in w_self.mro_w:
             try:
@@ -51,6 +49,17 @@
                 pass
         return None
 
+    def lookup_where(w_self, key):
+        # like lookup() but also returns the parent class in which the
+        # attribute was found
+        space = w_self.space
+        for w_class in w_self.mro_w:
+            try:
+                return w_class, w_class.dict_w[key]
+            except KeyError:
+                pass
+        return None, None
+
     def check_user_subclass(w_self, w_subtype):
         space = w_self.space
         if not space.is_true(space.isinstance(w_subtype, space.w_type)):
@@ -94,8 +103,7 @@
     # maybe invoke the __init__ of the type
     if space.is_true(space.isinstance(w_newobject, w_type)):
         w_descr = space.lookup(w_newobject, '__init__')
-        if w_descr is not None:
-            space.get_and_call(w_descr, w_newobject, w_args, w_kwds)
+        space.get_and_call(w_descr, w_newobject, w_args, w_kwds)
     return w_newobject
 
 def issubtype__Type_Type(space, w_type1, w_type2):



More information about the Pypy-commit mailing list