[pypy-svn] r73347 - in pypy/trunk/pypy/annotation: . test

benjamin at codespeak.net benjamin at codespeak.net
Sun Apr 4 04:43:45 CEST 2010


Author: benjamin
Date: Sun Apr  4 04:43:43 2010
New Revision: 73347

Modified:
   pypy/trunk/pypy/annotation/bookkeeper.py
   pypy/trunk/pypy/annotation/description.py
   pypy/trunk/pypy/annotation/test/test_annrpython.py
Log:
allow constant methods to have their attributes taken

Modified: pypy/trunk/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/trunk/pypy/annotation/bookkeeper.py	(original)
+++ pypy/trunk/pypy/annotation/bookkeeper.py	Sun Apr  4 04:43:43 2010
@@ -523,7 +523,7 @@
                         self.getdesc(pyobj.im_func),            # funcdesc
                         self.getuniqueclassdef(origincls),      # originclassdef
                         classdef,                               # selfclassdef
-                        name)
+                        name, pyobj=pyobj)
             else:
                 # must be a frozen pre-built constant, but let's check
                 try:
@@ -552,7 +552,7 @@
         return result
 
     def getmethoddesc(self, funcdesc, originclassdef, selfclassdef, name,
-                      flags={}):
+                      flags={}, pyobj=None):
         flagskey = flags.items()
         flagskey.sort()
         key = funcdesc, originclassdef, selfclassdef, name, tuple(flagskey)
@@ -560,7 +560,7 @@
             return self.methoddescs[key]
         except KeyError:
             result = description.MethodDesc(self, funcdesc, originclassdef,
-                                            selfclassdef, name, flags)
+                                            selfclassdef, name, flags, pyobj)
             self.methoddescs[key] = result
             return result
 

Modified: pypy/trunk/pypy/annotation/description.py
==============================================================================
--- pypy/trunk/pypy/annotation/description.py	(original)
+++ pypy/trunk/pypy/annotation/description.py	Sun Apr  4 04:43:43 2010
@@ -689,8 +689,8 @@
     knowntype = types.MethodType
 
     def __init__(self, bookkeeper, funcdesc, originclassdef, 
-                 selfclassdef, name, flags={}):
-        super(MethodDesc, self).__init__(bookkeeper)
+                 selfclassdef, name, flags={}, pyobj=None):
+        super(MethodDesc, self).__init__(bookkeeper, pyobj)
         self.funcdesc = funcdesc
         self.originclassdef = originclassdef
         self.selfclassdef = selfclassdef

Modified: pypy/trunk/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/trunk/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/trunk/pypy/annotation/test/test_annrpython.py	Sun Apr  4 04:43:43 2010
@@ -1751,6 +1751,23 @@
         s = a.build_types(f, [bool])
         assert s == annmodel.SomeString(can_be_None=True)
 
+    def test_method_hasattr(self):
+        class X:
+            def m(self):
+                return 4
+            m.attr = 23
+            def x(self, string):
+                return string
+        x = X()
+        m = x.m
+        def f(string):
+            if hasattr(m, "attr"):
+                return x.x(string)
+            return x.m()
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [str])
+        assert s == annmodel.SomeString()
+
     def test_dont_see_AttributeError_clause(self):
         class Stuff:
             def _freeze_(self):



More information about the Pypy-commit mailing list