[pypy-svn] r10700 - in pypy/dist/pypy: annotation annotation/test translator translator/test

arigo at codespeak.net arigo at codespeak.net
Fri Apr 15 19:32:11 CEST 2005


Author: arigo
Date: Fri Apr 15 19:32:11 2005
New Revision: 10700

Added:
   pypy/dist/pypy/annotation/listdef.py   (contents, props changed)
Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/annotation/factory.py
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/annotation/test/test_model.py
   pypy/dist/pypy/annotation/unaryop.py
   pypy/dist/pypy/translator/annrpython.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
Replaced ListFactory with ListDef, as discussed on IRC.  The goal is to get
rid of factory.py altogether.  I guess I should write some doc somewhere else
than in this check-in message...



Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Fri Apr 15 19:32:11 2005
@@ -227,8 +227,8 @@
 class __extend__(pairtype(SomeList, SomeList)):
 
     def union((lst1, lst2)):
-        return SomeList(setunion(lst1.factories, lst2.factories),
-                        s_item = unionof(lst1.s_item, lst2.s_item))
+        lst1.listdef.merge(lst2.listdef)
+        return lst1
 
     add = union
 
@@ -300,16 +300,16 @@
         return lst1
 
     def getitem((lst1, int2)):
-        return lst1.s_item
+        return lst1.listdef.read_item()
 
     def setitem((lst1, int2), s_value):
-        generalize(lst1.factories, s_value)
+        lst1.listdef.generalize(s_value)
 
 
 class __extend__(pairtype(SomeList, SomeSlice)):
 
     def getitem((lst, slic)):
-        return SomeList(lst.factories, lst.s_item)
+        return lst
 
 
 class __extend__(pairtype(SomeString, SomeSlice)):

Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Fri Apr 15 19:32:11 2005
@@ -7,6 +7,7 @@
 from pypy.tool.ansi_print import ansi_print
 from pypy.annotation.model import *
 from pypy.annotation.classdef import ClassDef
+from pypy.annotation.listdef import ListDef, MOST_GENERAL_LISTDEF
 from pypy.tool.tls import tlsobject
 from pypy.tool.hack import func_with_new_name
 from pypy.interpreter.pycode import CO_VARARGS
@@ -49,6 +50,7 @@
         self.pbccache = {}
         self.pbctypes = {}
         self.seen_mutable = {}
+        self.listdefs = {}       # map position_keys to ListDefs
         
         # mapping position -> most general result, for call sites calling
         # argtypes specialized functions
@@ -99,6 +101,22 @@
             self.userclasseslist.append(cdef)
             return self.userclasses[cls]
 
+    def getlistdef(self):
+        """Get the ListDef associated with the current position."""
+        try:
+            listdef = self.listdefs[self.position_key]
+        except KeyError:
+            listdef = self.listdefs[self.position_key] = ListDef(self)
+        return listdef
+
+    def newlist(self, *s_values):
+        """Make a SomeList associated with the current position, general
+        enough to contain the s_values as items."""
+        listdef = self.getlistdef()
+        for s_value in s_values:
+            listdef.generalize(s_value)
+        return SomeList(listdef)
+
 
     def immutablevalue(self, x):
         """The most precise SomeValue instance that contains the
@@ -118,7 +136,7 @@
             result = SomeFloat()
         elif tp is list:
             items_s = [self.immutablevalue(e) for e in x]
-            result = SomeList({}, unionof(*items_s))
+            result = SomeList(ListDef(self, unionof(*items_s)))
         elif tp is dict:   # exactly a dict
             keys_s   = [self.immutablevalue(e) for e in x.keys()]
             values_s = [self.immutablevalue(e) for e in x.values()]
@@ -197,7 +215,7 @@
         elif t is float:
             return SomeFloat()
         elif t is list:
-            return SomeList(factories={})
+            return SomeList(MOST_GENERAL_LISTDEF)
         # can't do dict, tuple
         elif t.__module__ != '__builtin__':
             classdef = self.getclassdef(t)

Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Fri Apr 15 19:32:11 2005
@@ -9,7 +9,6 @@
 from pypy.annotation.model import SomeList, SomeString, SomeTuple, SomeSlice
 from pypy.annotation.model import SomeFloat, unionof
 from pypy.annotation.bookkeeper import getbookkeeper
-from pypy.annotation.factory import ListFactory
 from pypy.objspace.flow.model import Constant
 import pypy.tool.rarithmetic
 
@@ -18,9 +17,7 @@
     return getbookkeeper().immutablevalue(x)
 
 def builtin_range(*args):
-    factory = getbookkeeper().getfactory(ListFactory)
-    factory.generalize(SomeInteger())  # XXX nonneg=...
-    return factory.create()
+    return getbookkeeper().newlist(SomeInteger())  # XXX nonneg=...
 
 builtin_xrange = builtin_range # xxx for now allow it
 
@@ -107,18 +104,14 @@
     return SomeObject()
 
 def builtin_list(s_iterable):
-    factory = getbookkeeper().getfactory(ListFactory)
     s_iter = s_iterable.iter()
-    factory.generalize(s_iter.next())
-    return factory.create()
+    return getbookkeeper().newlist(s_iter.next())
 
 def builtin_zip(s_iterable1, s_iterable2):
-    factory = getbookkeeper().getfactory(ListFactory)
     s_iter1 = s_iterable1.iter()
     s_iter2 = s_iterable2.iter()
     s_tup = SomeTuple((s_iter1.next(),s_iter2.next()))
-    factory.generalize(s_tup)
-    return factory.create()
+    return getbookkeeper().newlist(s_tup)
 
 def builtin_min(*s_values):
     if len(s_values) == 1: # xxx do we support this?

Modified: pypy/dist/pypy/annotation/factory.py
==============================================================================
--- pypy/dist/pypy/annotation/factory.py	(original)
+++ pypy/dist/pypy/annotation/factory.py	Fri Apr 15 19:32:11 2005
@@ -11,47 +11,23 @@
 from pypy.annotation.bookkeeper import getbookkeeper
 
 
-class BlockedInference(Exception):
-    """This exception signals the type inference engine that the situation
-    is currently blocked, and that it should try to progress elsewhere."""
-
-    def __init__(self, info=None):
-        try:
-            self.annotator = getbookkeeper().annotator
-            self.break_at = getbookkeeper().position_key
-        except AttributeError:
-            self.break_at = None
-        self.info = info
-
-    def __repr__(self):
-        if self.info:
-            info = "[%s]" % self.info
-        else:
-            info = ""
-        if not self.break_at:
-            break_at = "?"
-        else:
-            break_at = self.annotator.whereami(self.break_at)
-        return "<BlockedInference break_at %s %s>" %(break_at, info)
-
-    __str__ = __repr__
 
 
-class ListFactory:
-    s_item = SomeImpossibleValue()
+##class ListFactory:
+##    s_item = SomeImpossibleValue()
 
-    def __repr__(self):
-        return '%s(s_item=%r)' % (self.__class__.__name__, self.s_item)
+##    def __repr__(self):
+##        return '%s(s_item=%r)' % (self.__class__.__name__, self.s_item)
 
-    def create(self):
-        return SomeList(factories = {self: True}, s_item = self.s_item)
+##    def create(self):
+##        return SomeList(factories = {self: True}, s_item = self.s_item)
 
-    def generalize(self, s_new_item):
-        if not self.s_item.contains(s_new_item):
-            self.s_item = unionof(self.s_item, s_new_item)
-            return True
-        else:
-            return False
+##    def generalize(self, s_new_item):
+##        if not self.s_item.contains(s_new_item):
+##            self.s_item = unionof(self.s_item, s_new_item)
+##            return True
+##        else:
+##            return False
 
 
 class DictFactory:
@@ -85,4 +61,4 @@
     if modified:
         for factory in modified:
             factory.bookkeeper.annotator.reflowfromposition(factory.position_key)
-        raise BlockedInference   # reflow now
+        ##raise BlockedInference   # reflow now

Added: pypy/dist/pypy/annotation/listdef.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/annotation/listdef.py	Fri Apr 15 19:32:11 2005
@@ -0,0 +1,61 @@
+from pypy.annotation.model import SomeObject, SomeImpossibleValue, unionof
+
+
+class ListItem:
+
+    def __init__(self, bookkeeper, s_value):
+        self.s_value = s_value
+        self.bookkeeper = bookkeeper
+        self.itemof = {}  # set of all ListDefs using this ListItem
+        self.read_locations = {}
+
+    def merge(self, other):
+        if self is other:
+            return
+        self.itemof.update(other.itemof)
+        self.read_locations.update(other.read_locations)
+        for listdef in self.itemof:
+            listdef.listitem = self   # which should patch all refs to 'other'
+        self.generalize(other.s_value)
+
+    def generalize(self, s_other_value):
+        s_new_value = unionof(self.s_value, s_other_value)
+        if s_new_value == self.s_value:
+            return
+        self.s_value = s_new_value
+        # reflow from all reading points
+        for position_key in self.read_locations:
+            self.bookkeeper.annotator.reflowfromposition(position_key)
+
+
+class ListDef:
+    """A list definition remembers how general the items in that particular
+    list have to be.  Every list creation makes a new ListDef, and the union
+    of two lists merges the ListItems that each ListDef stores."""
+
+    def __init__(self, bookkeeper, s_item=SomeImpossibleValue()):
+        self.listitem = ListItem(bookkeeper, s_item)
+        self.listitem.itemof[self] = True
+        self.bookkeeper = bookkeeper
+
+    def read_item(self, position_key=None):
+        if position_key is None:
+            if self.bookkeeper is None:   # for tests
+                from pypy.annotation.bookkeeper import getbookkeeper
+                position_key = getbookkeeper().position_key
+            else:
+                position_key = self.bookkeeper.position_key
+        self.listitem.read_locations[position_key] = True
+        return self.listitem.s_value
+
+    def same_as(self, other):
+        return self.listitem is other.listitem
+
+    def merge(self, other):
+        self.listitem.merge(other.listitem)
+
+    def generalize(self, s_value):
+        self.listitem.generalize(s_value)
+
+
+MOST_GENERAL_LISTDEF = ListDef(None, SomeObject())

Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Fri Apr 15 19:32:11 2005
@@ -131,9 +131,12 @@
 class SomeList(SomeObject):
     "Stands for a homogenous list of any length."
     knowntype = list
-    def __init__(self, factories, s_item=SomeObject()):
-        self.factories = factories
-        self.s_item = s_item     # general enough for any element
+    def __init__(self, listdef):
+        assert hasattr(listdef, 'listitem')   # XXX remove me
+        self.listdef = listdef
+    def __eq__(self, other):
+        return (self.__class__ is other.__class__ and
+                self.listdef.same_as(other.listdef))
 
 
 class SomeSlice(SomeObject):

Modified: pypy/dist/pypy/annotation/test/test_model.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_model.py	(original)
+++ pypy/dist/pypy/annotation/test/test_model.py	Fri Apr 15 19:32:11 2005
@@ -1,15 +1,19 @@
 
 import autopath
 from pypy.annotation.model import *
+from pypy.annotation.listdef import ListDef
 
 
+listdef1 = ListDef(None, SomeTuple([SomeInteger(nonneg=True), SomeString()]))
+listdef2 = ListDef(None, SomeTuple([SomeInteger(nonneg=False), SomeString()]))
+
 s1 = SomeObject()
 s2 = SomeInteger(nonneg=True)
 s3 = SomeInteger(nonneg=False)
-s4 = SomeList({}, SomeTuple([SomeInteger(nonneg=True), SomeString()]))
-s5 = SomeList({}, SomeTuple([SomeInteger(nonneg=False), SomeString()]))
+s4 = SomeList(listdef1)
+s5 = SomeList(listdef2)
 s6 = SomeImpossibleValue()
-slist = [s1,s2,s3,s4,s5,s6]
+slist = [s1,s2,s3,s4,s6]  # not s5 -- unionof(s4,s5) modifies s4 and s5
 
 
 class C(object):
@@ -39,27 +43,25 @@
     assert s1 == SomeObject()
     assert s2 == SomeInteger(nonneg=True)
     assert s3 == SomeInteger(nonneg=False)
-    assert s4 == SomeList({}, SomeTuple([SomeInteger(nonneg=True), SomeString()]))
-    assert s5 == SomeList({}, SomeTuple([SomeInteger(nonneg=False), SomeString()]))
+    assert s4 == SomeList(listdef1)
+    assert s5 == SomeList(listdef2)
     assert s6 == SomeImpossibleValue()
 
 def test_contains():
     assert ([(s,t) for s in slist for t in slist if s.contains(t)] ==
-            [(s1,s1), (s1,s2), (s1,s3), (s1,s4), (s1,s5), (s1,s6),
-                      (s2,s2),                            (s2,s6),
-                      (s3,s2), (s3,s3),                   (s3,s6),
-                                        (s4,s4),          (s4,s6),
-                                        (s5,s4), (s5,s5), (s5,s6),
-                                                          (s6,s6)])
+            [(s1,s1), (s1,s2), (s1,s3), (s1,s4), (s1,s6),
+                      (s2,s2),                   (s2,s6),
+                      (s3,s2), (s3,s3),          (s3,s6),
+                                        (s4,s4), (s4,s6),
+                                                 (s6,s6)])
 
 def test_union():
     assert ([unionof(s,t) for s in slist for t in slist] ==
-            [s1, s1, s1, s1, s1, s1,
-             s1, s2, s3, s1, s1, s2,
-             s1, s3, s3, s1, s1, s3,
-             s1, s1, s1, s4, s5, s4,
-             s1, s1, s1, s5, s5, s5,
-             s1, s2, s3, s4, s5, s6])
+            [s1, s1, s1, s1, s1,
+             s1, s2, s3, s1, s2,
+             s1, s3, s3, s1, s3,
+             s1, s1, s1, s4, s4,
+             s1, s2, s3, s4, s6])
 
 def test_commonbase_simple():
     class A0: 
@@ -78,7 +80,16 @@
     assert commonbase(A1,A0) is A0
     assert commonbase(A1,A1) is A1
     assert commonbase(A2,B2) is object 
-    assert commonbase(A2,B3) is A0 
+    assert commonbase(A2,B3) is A0
+
+def test_list_union():
+    listdef1 = ListDef(None, SomeInteger(nonneg=True))
+    listdef2 = ListDef(None, SomeInteger(nonneg=False))
+    s1 = SomeList(listdef1)
+    s2 = SomeList(listdef2)
+    assert s1 != s2
+    s3 = unionof(s1, s2)
+    assert s1 == s2 == s3
 
 if __name__ == '__main__':
     for name, value in globals().items():

Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Fri Apr 15 19:32:11 2005
@@ -11,7 +11,7 @@
 from pypy.annotation.model import SomeInstance, SomeBuiltin, SomeFloat
 from pypy.annotation.model import SomeIterator, SomePBC, new_or_old_class
 from pypy.annotation.model import unionof, set, setunion, missing_operation
-from pypy.annotation.factory import BlockedInference, generalize, ListFactory
+from pypy.annotation.factory import generalize
 from pypy.annotation.bookkeeper import getbookkeeper
 from pypy.annotation.classdef import isclassdef
 from pypy.annotation import builtin
@@ -194,10 +194,10 @@
         pair(lst, SomeInteger()).setitem(s_value)
         
     def method_pop(lst, s_index=None):
-        return lst.s_item
+        return lst.listdef.read_item()
 
     def iter(lst):
-        return SomeIterator(lst.s_item)
+        return SomeIterator(lst.listdef.read_item())
 
 class __extend__(SomeDict):
     def iter(dct):
@@ -210,19 +210,13 @@
         generalize(dct1.factories, dct2.s_key, dct2.s_value)
 
     def method_keys(dct):
-        factory = getbookkeeper().getfactory(ListFactory)
-        factory.generalize(dct.s_key)
-        return factory.create()
+        return getbookkeeper().newlist(dct.s_key)
 
     def method_values(dct):
-        factory = getbookkeeper().getfactory(ListFactory)
-        factory.generalize(dct.s_value)
-        return factory.create()
+        return getbookkeeper().newlist(dct.s_value)
 
     def method_items(dct):
-        factory = getbookkeeper().getfactory(ListFactory)
-        factory.generalize(SomeTuple((dct.s_key, dct.s_value)))
-        return factory.create()
+        return getbookkeeper().newlist(SomeTuple((dct.s_key, dct.s_value)))
         
 
 class __extend__(SomeString):
@@ -237,9 +231,7 @@
         return SomeInteger(nonneg=True)
 
     def method_split(str, patt): # XXX
-        factory = getbookkeeper().getfactory(ListFactory)
-        factory.generalize(SomeString())
-        return factory.create()    
+        return getbookkeeper().newlist(SomeString())
 
 
 class __extend__(SomeChar):

Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Fri Apr 15 19:32:11 2005
@@ -4,7 +4,7 @@
 from pypy.tool.ansi_print import ansi_print
 from pypy.annotation import model as annmodel
 from pypy.annotation.model import pair
-from pypy.annotation.factory import ListFactory, DictFactory, BlockedInference
+from pypy.annotation.factory import DictFactory
 from pypy.annotation.bookkeeper import Bookkeeper
 from pypy.objspace.flow.model import Variable, Constant, undefined_value
 from pypy.objspace.flow.model import SpaceOperation, FunctionGraph
@@ -441,12 +441,12 @@
         # boom
         for arg in argcells:
             if isinstance(arg, annmodel.SomeImpossibleValue):
-                raise BlockedInference(info=op)
+                raise BlockedInference(self, info=op)
         resultcell = consider_meth(*argcells)
         if resultcell is None:
             resultcell = annmodel.SomeImpossibleValue()  # no return value
         elif resultcell == annmodel.SomeImpossibleValue():
-            raise BlockedInference(info=op)  # the operation cannot succeed
+            raise BlockedInference(self, info=op) # the operation cannot succeed
         assert isinstance(resultcell, annmodel.SomeObject)
         assert isinstance(op.result, Variable)
         self.setbinding(op.result, resultcell)  # bind resultcell to op.result
@@ -479,10 +479,7 @@
         return annmodel.SomeTuple(items = args)
 
     def consider_op_newlist(self, *args):
-        factory = self.bookkeeper.getfactory(ListFactory)
-        for a in args:
-            factory.generalize(a)
-        return factory.create()
+        return self.bookkeeper.newlist(*args)
 
     def consider_op_newdict(self, *args):
         assert not args, "XXX only supports newdict([])"
@@ -495,3 +492,29 @@
 
 class CannotSimplify(Exception):
     pass
+
+
+class BlockedInference(Exception):
+    """This exception signals the type inference engine that the situation
+    is currently blocked, and that it should try to progress elsewhere."""
+
+    def __init__(self, annotator, info=None):
+        self.annotator = annotator
+        try:
+            self.break_at = annotator.bookkeeper.position_key
+        except AttributeError:
+            self.break_at = None
+        self.info = info
+
+    def __repr__(self):
+        if self.info:
+            info = "[%s]" % self.info
+        else:
+            info = ""
+        if not self.break_at:
+            break_at = "?"
+        else:
+            break_at = self.annotator.whereami(self.break_at)
+        return "<BlockedInference break_at %s %s>" %(break_at, info)
+
+    __str__ = __repr__

Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py	Fri Apr 15 19:32:11 2005
@@ -5,11 +5,20 @@
 
 from pypy.translator.annrpython import RPythonAnnotator, annmodel
 from pypy.translator.translator import Translator
+from pypy.annotation.listdef import ListDef
 from pypy.objspace.flow.model import *
 from pypy.tool.rarithmetic import r_uint
 
 from pypy.translator.test import snippet
 
+def listitem(s_list):
+    assert isinstance(s_list, annmodel.SomeList)
+    return s_list.listdef.listitem.s_value
+
+def somelist(s_type=annmodel.SomeObject()):
+    return annmodel.SomeList(ListDef(None, s_type))
+
+
 class TestAnnonateTestCase:
     objspacename = 'flow'
 
@@ -119,8 +128,7 @@
         a = RPythonAnnotator()
         end_cell = a.build_types(snippet.poor_man_rev_range, [int])
         # result should be a list of integers
-        assert end_cell.knowntype == list
-        assert end_cell.s_item.knowntype == int
+        assert listitem(end_cell).knowntype == int
 
     def test_factorial(self):
         a = RPythonAnnotator()
@@ -174,8 +182,7 @@
         a = RPythonAnnotator()
         s = a.build_types(snippet.poor_man_range, [int])
         # result should be a list of integers
-        assert s.knowntype == list
-        assert s.s_item.knowntype == int
+        assert listitem(s).knowntype == int
 
     def test_methodcall1(self):
         a = RPythonAnnotator()
@@ -247,15 +254,13 @@
         a = RPythonAnnotator()
         s = a.build_types(snippet.call_five, [])
         # returns should be a list of constants (= 5)
-        assert isinstance(s, annmodel.SomeList)
-        assert s.s_item == a.bookkeeper.immutablevalue(5)
+        assert listitem(s) == a.bookkeeper.immutablevalue(5)
 
     def test_call_five_six(self):
         a = RPythonAnnotator()
         s = a.build_types(snippet.call_five_six, [])
         # returns should be a list of positive integers
-        assert isinstance(s, annmodel.SomeList)
-        assert s.s_item == annmodel.SomeInteger(nonneg=True)
+        assert listitem(s) == annmodel.SomeInteger(nonneg=True)
 
     def test_constant_result(self):
         a = RPythonAnnotator()
@@ -370,11 +375,11 @@
         # the annotator (it doesn't check that they operate property, though)
         for example, methname, s_example in [
             ('', 'join',    annmodel.SomeString()),
-            ([], 'append',  annmodel.SomeList({})), 
-            ([], 'extend',  annmodel.SomeList({})),           
-            ([], 'reverse', annmodel.SomeList({})),
-            ([], 'insert',  annmodel.SomeList({})),
-            ([], 'pop',     annmodel.SomeList({})),
+            ([], 'append',  somelist()), 
+            ([], 'extend',  somelist()),           
+            ([], 'reverse', somelist()),
+            ([], 'insert',  somelist()),
+            ([], 'pop',     somelist()),
             ]:
             constmeth = getattr(example, methname)
             s_constmeth = iv(constmeth)
@@ -411,13 +416,13 @@
 
     def test_simple_zip(self):
         a = RPythonAnnotator()
-        x = annmodel.SomeList({}, annmodel.SomeInteger())
-        y = annmodel.SomeList({}, annmodel.SomeString())
+        x = somelist(annmodel.SomeInteger())
+        y = somelist(annmodel.SomeString())
         s = a.build_types(snippet.simple_zip, [x,y])
         assert s.knowntype == list
-        assert s.s_item.knowntype == tuple
-        assert s.s_item.items[0].knowntype == int
-        assert s.s_item.items[1].knowntype == str
+        assert listitem(s).knowntype == tuple
+        assert listitem(s).items[0].knowntype == int
+        assert listitem(s).items[1].knowntype == str
         
     def test_dict_copy(self):
         a = RPythonAnnotator()
@@ -443,33 +448,28 @@
     def test_dict_keys(self):
         a = RPythonAnnotator()
         s = a.build_types(snippet.dict_keys, [])
-        assert isinstance(s, annmodel.SomeList)
-        assert isinstance(s.s_item, annmodel.SomeString)
+        assert isinstance(listitem(s), annmodel.SomeString)
 
     def test_dict_keys2(self):
         a = RPythonAnnotator()
         s = a.build_types(snippet.dict_keys2, [])
-        assert isinstance(s, annmodel.SomeList)
-        assert not isinstance(s.s_item, annmodel.SomeString)
+        assert not isinstance(listitem(s), annmodel.SomeString)
 
     def test_dict_values(self):
         a = RPythonAnnotator()
         s = a.build_types(snippet.dict_values, [])
-        assert isinstance(s, annmodel.SomeList)
-        assert isinstance(s.s_item, annmodel.SomeString)
+        assert isinstance(listitem(s), annmodel.SomeString)
     
     def test_dict_values2(self):
         a = RPythonAnnotator()
         s = a.build_types(snippet.dict_values2, [])
-        assert isinstance(s, annmodel.SomeList)
-        assert not isinstance(s.s_item, annmodel.SomeString)
+        assert not isinstance(listitem(s), annmodel.SomeString)
 
     def test_dict_items(self):
         a = RPythonAnnotator()
         s = a.build_types(snippet.dict_items, [])
-        assert isinstance(s, annmodel.SomeList)
-        assert isinstance(s.s_item, annmodel.SomeTuple)
-        s_key, s_value = s.s_item.items
+        assert isinstance(listitem(s), annmodel.SomeTuple)
+        s_key, s_value = listitem(s).items
         assert isinstance(s_key, annmodel.SomeString)
         assert isinstance(s_value, annmodel.SomeInteger)
 
@@ -549,10 +549,10 @@
         assert s.knowntype == snippet.B
         Even_def = a.getuserclasses()[snippet.Even]
         Odd_def = a.getuserclasses()[snippet.Odd]
-        assert Even_def.attrs['x'].s_value.s_item.knowntype == snippet.Odd
-        assert Even_def.attrs['y'].s_value.s_item.knowntype == snippet.Even
-        assert Odd_def.attrs['x'].s_value.s_item.knowntype == snippet.Even
-        assert Odd_def.attrs['y'].s_value.s_item.knowntype == snippet.Odd        
+        assert listitem(Even_def.attrs['x'].s_value).knowntype == snippet.Odd
+        assert listitem(Even_def.attrs['y'].s_value).knowntype == snippet.Even
+        assert listitem(Odd_def.attrs['x'].s_value).knowntype == snippet.Even
+        assert listitem(Odd_def.attrs['y'].s_value).knowntype == snippet.Odd        
 
     def test_flow_rev_numbers(self):
         a = RPythonAnnotator()
@@ -702,8 +702,7 @@
             return lst
         a = RPythonAnnotator()
         s = a.build_types(f, [int])
-        assert isinstance(s, annmodel.SomeList)
-        assert s.s_item == s
+        assert listitem(s) == s
 
     def test_harmonic(self):
         a = RPythonAnnotator()
@@ -761,8 +760,8 @@
         a = RPythonAnnotator()
         s = a.build_types(g,[])
         l1, l2 = s.items
-        assert l1.s_item.knowntype == int
-        assert l2.s_item.knowntype == str
+        assert listitem(l1).knowntype == int
+        assert listitem(l2).knowntype == str
 
         access_sets = a.getpbcaccesssets()
 
@@ -825,8 +824,7 @@
             return g(l)
         a = RPythonAnnotator()
         s = a.build_types(f, [])
-        assert s.knowntype == list
-        assert s.s_item.knowntype == T
+        assert listitem(s).knowntype == T
           
     def test_assert_type_is_list_doesnt_lose_info(self):
         class T(object):
@@ -839,8 +837,7 @@
             return g(l)
         a = RPythonAnnotator()
         s = a.build_types(f, [])
-        assert s.knowntype == list
-        assert s.s_item.knowntype == T
+        assert listitem(s).knowntype == T
 
     def test_int_str_mul(self):
         def f(x,a,b):



More information about the Pypy-commit mailing list