[pypy-svn] r20257 - in pypy/branch/somepbc-refactoring/pypy: annotation translator/test
arigo at codespeak.net
arigo at codespeak.net
Fri Nov 25 21:09:04 CET 2005
Author: arigo
Date: Fri Nov 25 21:09:03 2005
New Revision: 20257
Modified:
pypy/branch/somepbc-refactoring/pypy/annotation/classdef.py
pypy/branch/somepbc-refactoring/pypy/translator/test/test_annrpython.py
Log:
issue129 resolved
(pedronis, arigo)
The previous check-in in the somepbc-refactoring branch
allows us to support storing bound methods as instance attributes
with a one-line change.
This kind of construction was needed by Christian for the marshal
code. Maybe we can still do that now :-)
Modified: pypy/branch/somepbc-refactoring/pypy/annotation/classdef.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/classdef.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/classdef.py Fri Nov 25 21:09:03 2005
@@ -307,7 +307,10 @@
meth = False
check_for_missing_attrs = False
for desc in pbc.descriptions:
- if isinstance(desc, description.MethodDesc):
+ # pick methods but ignore already-bound methods, which can come
+ # from an instance attribute
+ if (isinstance(desc, description.MethodDesc)
+ and desc.selfclassdef is None):
meth = True
methclassdef = desc.originclassdef
if methclassdef is not self and methclassdef.issubclass(self):
Modified: pypy/branch/somepbc-refactoring/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/test/test_annrpython.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/test/test_annrpython.py Fri Nov 25 21:09:03 2005
@@ -1780,6 +1780,54 @@
s = a.build_types(f1, [int])
assert s.knowntype == int
+ def test_stored_bound_method(self):
+ # issue 129
+ class H:
+ def h(self):
+ return 42
+ class C:
+ def __init__(self, func):
+ self.f = func
+ def do(self):
+ return self.f()
+ def g():
+ h = H()
+ c = C(h.h)
+ return c.do()
+
+ a = self.RPythonAnnotator()
+ s = a.build_types(g, [])
+ assert s.is_constant()
+ assert s.const == 42
+
+ def test_stored_bound_method_2(self):
+ # issue 129
+ class H:
+ pass
+ class H1(H):
+ def h(self):
+ return 42
+ class H2(H):
+ def h(self):
+ return 17
+ class C:
+ def __init__(self, func):
+ self.f = func
+ def do(self):
+ return self.f()
+ def g(flag):
+ if flag:
+ h = H1()
+ else:
+ h = H2()
+ c = C(h.h)
+ return c.do()
+
+ a = self.RPythonAnnotator()
+ s = a.build_types(g, [int])
+ assert s.knowntype == int
+ assert not s.is_constant()
+
def g(n):
return [0,1,2,n]
More information about the Pypy-commit
mailing list