[pypy-svn] r13458 - pypy/dist/pypy/rpython/test

arigo at codespeak.net arigo at codespeak.net
Wed Jun 15 22:56:39 CEST 2005


Author: arigo
Date: Wed Jun 15 22:56:38 2005
New Revision: 13458

Modified:
   pypy/dist/pypy/rpython/test/test_interp.py
Log:
Actually, you don't need so many strange '._obj0' accesses to fish the
information.  All names starting with '_' are meant to be hidden and not used
from outside.  There are some exception that are ok to use in some specific
cases.  Note that at places like that we usually cannot remove the '_' because
it might collide with an attribute or field name defined by the caller.  Some
guidelines of '_' attributes that are kind of ok to use:

* '_obj' on a _ptr object *in special cases only*.  Normally, the _struct and
  other classes are only an implementation detail; no instance of _struct
  should ever escape lltype.  The _ptr provides an interface to all low-level
  operations on them.  (Something missing now is an interface to access
  attributes of _func and _pyobject; right now there is no other way than via
  '_obj'.)

* '_name', '_names', '_flds' on a Struct, to introspect its shape.

Other attributes should have accessor functions, e.g. don't read '_TYPE' but
call typeOf(), which works for primitive objects too.  From the type, you can
fish for most information: '.TO' to dereference a Ptr, '.OF' to get at the
items of an Array, or '.fieldname' to get at the type of a field in a Struct.  
FuncTypes have an ARGS list and a RESULT.


Modified: pypy/dist/pypy/rpython/test/test_interp.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_interp.py	(original)
+++ pypy/dist/pypy/rpython/test/test_interp.py	Wed Jun 15 22:56:38 2005
@@ -1,6 +1,7 @@
 
 import py
 py.magic.autopath()
+from pypy.rpython.lltype import typeOf
 from pypy.rpython.rtyper import RPythonTyper 
 from pypy.rpython.interp import LLInterpreter, RPythonError
 from pypy.translator.translator import Translator 
@@ -55,7 +56,7 @@
         val1 = t(3)
         val2 = t(4)
         gcres = interpret(comparisons, [val1, val2])
-        res = [getattr(gcres._obj0, x) for x in gcres._obj0._TYPE._names]
+        res = [getattr(gcres, x) for x in typeOf(gcres).TO._names]
         assert res == [True, True, False, True, False, False]
 
 def XXXtest_some_builtin(): 



More information about the Pypy-commit mailing list