[pypy-svn] r25319 - in pypy/dist/pypy: annotation annotation/test translator/c/test
pedronis at codespeak.net
pedronis at codespeak.net
Tue Apr 4 19:54:12 CEST 2006
Author: pedronis
Date: Tue Apr 4 19:54:07 2006
New Revision: 25319
Modified:
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/test/test_annrpython.py
pypy/dist/pypy/translator/c/test/test_genc.py
Log:
25277 broke some annotation cases in a hard way (contains invariant broken)!
for example: test_inline.py test_inline_var_exception
Fix for that.
The specific situation now is tested in test_annotate_type.
Added a test in test_genc for what I suppose (no tests) was the behavior
wanted by 25277.
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Tue Apr 4 19:54:07 2006
@@ -390,13 +390,14 @@
if result is None:
result = SomeObject()
else:
- # note that the print support functions are __builtin__
- if hasattr(x, '__module__') and x.__module__ != '__builtin__' \
- or tp in (types.FunctionType, types.MethodType):
- result = SomePBC([self.getdesc(x)])
- else:
- # a builtin that we don't handle specially
+ if (self.annotator.policy.allow_someobjects
+ and getattr(x, '__module__', None) == '__builtin__'
+ # XXX note that the print support functions are __builtin__
+ and tp not in (types.FunctionType, types.MethodType)):
result = SomeObject()
+ result.knowntype = tp # at least for types this needs to be correct
+ else:
+ result = SomePBC([self.getdesc(x)])
elif hasattr(x, '__class__') \
and x.__class__.__module__ != '__builtin__':
# user-defined classes can define a method _freeze_(), which
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 Tue Apr 4 19:54:07 2006
@@ -1945,6 +1945,22 @@
graph = tgraphof(t, A.__del__.im_func)
assert graph.startblock in a.annotated
+ def test_annotate_type(self):
+ class A:
+ pass
+ x = [A(), A()]
+ def witness(t):
+ return type(t)
+ def get(i):
+ return x[i]
+ def f(i):
+ witness(None)
+ return witness(get(i))
+
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [int])
+ assert s.__class__ == annmodel.SomeObject
+ assert s.knowntype == type
def g(n):
return [0,1,2,n]
Modified: pypy/dist/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_genc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_genc.py Tue Apr 4 19:54:07 2006
@@ -398,4 +398,12 @@
before = g(obj)
f(2, obj)
after = g(obj)
- assert before == after
\ No newline at end of file
+ assert before == after
+
+def test_long_pyobj():
+ def f(x):
+ return long(x)
+ f = compile(f, [int])
+ res = f(2)
+ assert isinstance(res, long)
+ assert res == 2L
More information about the Pypy-commit
mailing list