[pypy-svn] r26842 - in pypy/dist/pypy/annotation: . test

arigo at codespeak.net arigo at codespeak.net
Sat May 6 09:35:54 CEST 2006


Author: arigo
Date: Sat May  6 09:35:51 2006
New Revision: 26842

Modified:
   pypy/dist/pypy/annotation/description.py
   pypy/dist/pypy/annotation/test/test_annrpython.py
Log:
Annotate classes that have __slots__.  The slots are ignored, but they
used to confuse the annotator because they show up in the class.



Modified: pypy/dist/pypy/annotation/description.py
==============================================================================
--- pypy/dist/pypy/annotation/description.py	(original)
+++ pypy/dist/pypy/annotation/description.py	Sat May  6 09:35:51 2006
@@ -395,6 +395,10 @@
                 # that the py lib has its own AssertionError.__init__ which
                 # is of type FunctionType.  But bookkeeper.immutablevalue()
                 # will do the right thing in s_get_value().
+
+            if type(value) is MemberDescriptorType:
+                # skip __slots__, showing up in the class as 'member' objects
+                continue
             self.classdict[name] = Constant(value)
 
     def getclassdef(self, key):
@@ -759,3 +763,10 @@
 
     def rowkey(self):
         return self.funcdesc
+
+# ____________________________________________________________
+
+class Sample(object):
+    __slots__ = 'x'
+MemberDescriptorType = type(Sample.x)
+del Sample

Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py	Sat May  6 09:35:51 2006
@@ -2060,6 +2060,20 @@
         assert isinstance(s.items[1], annmodel.SomePBC)
         assert len(s.items[1].descriptions) == 1
 
+    def test_slots(self):
+        # check that the annotator ignores slots instead of being
+        # confused by them showing up as 'member' objects in the class
+        class A(object):
+            __slots__ = ('a', 'b')
+        def f(x):
+            a = A()
+            a.b = x
+            return a.b
+
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [int])
+        assert s.knowntype == int
+
 
 def g(n):
     return [0,1,2,n]



More information about the Pypy-commit mailing list