[pypy-svn] r39970 - in pypy/dist/pypy: doc interpreter

gbrandl at codespeak.net gbrandl at codespeak.net
Mon Mar 5 21:28:51 CET 2007


Author: gbrandl
Date: Mon Mar  5 21:28:49 2007
New Revision: 39970

Modified:
   pypy/dist/pypy/doc/objspace.txt
   pypy/dist/pypy/interpreter/baseobjspace.py
Log:
(xoraxax, gbrandl) Document the new index() and getindex_w() object space methods
and rename an argument of the latter one.



Modified: pypy/dist/pypy/doc/objspace.txt
==============================================================================
--- pypy/dist/pypy/doc/objspace.txt	(original)
+++ pypy/dist/pypy/doc/objspace.txt	Mon Mar  5 21:28:49 2007
@@ -110,6 +110,11 @@
 ``call(w_callable, w_args, w_kwds):``
   Call a function with the given args and keywords.
 
+``index(w_obj):``
+  Implements the index lookup (new in CPython 2.5) on 'w_obj'. Will return a
+  wrapped integer or long, or raise a TypeError if the object doesn't have an
+  ``__index__`` special method.
+
 ``is_(w_x, w_y):``
   Implements 'w_x is w_y'. (Returns a wrapped result too!)
 
@@ -214,16 +219,28 @@
   value of the wrapped object w_x.
 
 ``int_w(w_x):``
-  If w_x is an application-level integer or long which can be converted without overflow to an integer, return an interpreter-level integer.  Otherwise raise TypeError or OverflowError.
+  If w_x is an application-level integer or long which can be converted without
+  overflow to an integer, return an interpreter-level integer.
+  Otherwise raise TypeError or OverflowError.
 
 ``bigint_w(w_x):``
-  If w_x is an application-level integer or long, return an interpreter-level rbigint. Otherwise raise TypeError.
+  If w_x is an application-level integer or long, return an interpreter-level rbigint.
+  Otherwise raise TypeError.
 
 ``str_w(w_x):``
-  If w_x is an application-level string, return an interpreter-level string.  Otherwise raise TypeError.
+  If w_x is an application-level string, return an interpreter-level string.
+  Otherwise raise TypeError.
 
 ``float_w(w_x):``
-  If w_x is an application-level float, integer or long, return interpreter-level float.  Otherwise raise TypeError or OverflowError in case of very large longs.
+  If w_x is an application-level float, integer or long, return interpreter-level float.
+  Otherwise raise TypeError or OverflowError in case of very large longs.
+
+``getindex_w(w_obj, w_exception=None):``
+  Call `index(w_obj)`. If the resulting integer or long object can be converted
+  to an interpreter-level int, return that. If not, return a clamped result if
+  `w_exception` is None, otherwise raise that exception on application-level.
+  (If w_obj can't be converted to an index, `index()` will raise an
+  application-level TypeError.)
 
 ``interp_w(RequiredClass, w_x, can_be_None=False):``
   If w_x is a wrapped instance of the given bytecode interpreter class,

Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Mon Mar  5 21:28:49 2007
@@ -785,14 +785,14 @@
             step  = 0
         return start, stop, step
 
-    def getindex_w(self, w_obj, exception=None):
+    def getindex_w(self, w_obj, w_exception=None):
         w_index = self.index(w_obj)
         try:
             index = self.int_w(w_index)
         except OperationError, err:
             if not err.match(self, self.w_OverflowError):
                 raise
-            if not exception:
+            if not w_exception:
                 # w_index is a long object
                 if w_index.get_sign() < 0:
                     return -sys.maxint-1
@@ -800,7 +800,7 @@
                     return sys.maxint
             else:
                 raise OperationError(
-                    exception, self.wrap(
+                    w_exception, self.wrap(
                     "cannot fit '%s' into an index-sized "
                     "integer" % self.type(w_obj).getname(self, '?')))
         else:



More information about the Pypy-commit mailing list