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

mwh at codespeak.net mwh at codespeak.net
Sun Jun 22 12:58:22 CEST 2003


Author: mwh
Date: Sun Jun 22 12:58:22 2003
New Revision: 924

Modified:
   pypy/trunk/src/pypy/interpreter/baseobjspace.py
   pypy/trunk/src/pypy/objspace/std/default.py
   pypy/trunk/src/pypy/objspace/std/objecttype.py
   pypy/trunk/src/pypy/objspace/std/objspace.py
Log:
support for the data/non-data descriptor distinction.


Modified: pypy/trunk/src/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/trunk/src/pypy/interpreter/baseobjspace.py	Sun Jun 22 12:58:22 2003
@@ -214,6 +214,8 @@
     ('next',            'next',      1, ['next']),  # iterator interface
     ('call',            'call',      3, ['__call__']),
     ('get',             'get',       3, ['__get__']),
+    ('set',             'set',       2, ['__set__']),
+    ('delete',          'delete',    2, ['__delete__']),
     ('new',             'new',       3, ['__new__']),
     ('init',            'init',      3, ['__init__']),
     ]

Modified: pypy/trunk/src/pypy/objspace/std/default.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/default.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/default.py	Sun Jun 22 12:58:22 2003
@@ -67,6 +67,9 @@
 def get__ANY_ANY_ANY(space, w_descr, w_inst, w_cls):
     return w_descr
 
+def is_data_descr__ANY(space, w_descr):
+    return 0
+
 def issubtype__ANY_ANY(space, w_one, w_two):
     # XXX -- mwh
     return space.newbool(0)

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	Sun Jun 22 12:58:22 2003
@@ -53,11 +53,29 @@
     if space.is_true(space.eq(w_attr, space.wrap('__class__'))):
         return w_type
 
+    # 1) look for descriptor
+    # 2) if data descriptor, call it
+    # 3) check __dict__
+    # 4) if present, return that
+    # 5) if descriptor found in 2), call that
+    # 6) raise AttrbuteError
+
+    w_descr = None
+
+    from typeobject import W_TypeObject
+    if isinstance(w_type, W_TypeObject):  # XXX must always be true at some point
+        try:
+            w_descr = w_type.lookup(w_attr)
+        except KeyError:
+            pass
+        else:
+            if space.is_data_descr(w_descr):
+                return space.get(w_descr, w_obj, w_type) # XXX 3rd arg is wrong
+    
     try:
         w_dict = space.getdict(w_obj)
     except OperationError, e:
-        # catch TypeError("unsupported type for getdict")
-        if not e.match(space, space.w_TypeError):
+        if not e.match(space, space.w_TypeError): # 'unsupported type for getdict'
             raise
     else:
         if space.is_true(space.eq(w_attr, space.wrap('__dict__'))):
@@ -65,21 +83,13 @@
         try:
             w_value = space.getitem(w_dict, w_attr)
         except OperationError, e:
-            # catch KeyErrors
             if not e.match(space, space.w_KeyError):
                 raise
         else:
             return w_value  # got a value from 'obj.__dict__[attr]'
 
-    # XXX implement lookup as a multimethod?
-    from typeobject import W_TypeObject
-    if isinstance(w_type, W_TypeObject):  # XXX must always be true at some point
-        try:
-            w_value = w_type.lookup(w_attr)
-        except KeyError:
-            pass
-        else:
-            return space.get(w_value, w_obj, w_type) # XXX 3rd arg is wrong
+    if w_descr is not None:
+        return space.get(w_descr, w_obj, w_type)
         
     raise OperationError(space.w_AttributeError, w_attr)
 

Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py	Sun Jun 22 12:58:22 2003
@@ -270,6 +270,7 @@
     delegate = DelegateMultiMethod()          # delegators
     unwrap  = MultiMethod('unwrap', 1, [])    # returns an unwrapped object
     is_true = MultiMethod('nonzero', 1, [])   # returns an unwrapped bool
+    is_data_descr = MultiMethod('is_data_descr', 1, []) # returns an unwrapped bool
     # XXX do something about __nonzero__ !
 
     getdict = MultiMethod('getdict', 1, [])  # get '.__dict__' attribute


More information about the Pypy-commit mailing list