[pypy-svn] r10667 - in pypy/dist/pypy: annotation translator/test
pedronis at codespeak.net
pedronis at codespeak.net
Fri Apr 15 15:36:05 CEST 2005
Author: pedronis
Date: Fri Apr 15 15:36:05 2005
New Revision: 10667
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/translator/test/test_annrpython.py
Log:
what we were doing with [assert] isinstance(.,list) was dangerous an losing info
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Fri Apr 15 15:36:05 2005
@@ -131,8 +131,10 @@
bk = getbookkeeper()
if bk is not None: # for testing
if hasattr(obj1,'is_type_of') and obj2.is_constant():
- r.knowntypedata = (obj1.is_type_of, bk.valueoftype(obj2.const))
- return r
+ if obj2.const != list: # in list case we are most likely bound to lose info
+ # we would also generate a factory-less list, not good either
+ r.knowntypedata = (obj1.is_type_of, bk.valueoftype(obj2.const))
+ return r
fn, block, i = bk.position_key
annotator = bk.annotator
op = block.operations[i]
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Fri Apr 15 15:36:05 2005
@@ -81,7 +81,9 @@
variables = [op.args[1]]
for variable in variables:
assert bk.annotator.binding(variable) == s_obj
- r.knowntypedata = (variables, bk.valueoftype(typ))
+ if typ != list: # in the list case we are most likely bound to lose info,
+ # we would also generate a factory-less list, not good either
+ r.knowntypedata = (variables, bk.valueoftype(typ))
return r
def builtin_hasattr(s_obj, s_attr):
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 15:36:05 2005
@@ -807,6 +807,35 @@
assert s.items[0].knowntype == C1
assert s.items[1].knowntype == C2
+ def test_assert_list_doesnt_lose_info(self):
+ class T(object):
+ pass
+ def g(l):
+ assert isinstance(l, list)
+ return l
+ def f():
+ l = [T()]
+ return g(l)
+ a = RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.knowntype == list
+ assert s.s_item.knowntype == T
+
+ def test_assert_type_is_list_doesnt_lose_info(self):
+ class T(object):
+ pass
+ def g(l):
+ assert type(l) is list
+ return l
+ def f():
+ l = [T()]
+ return g(l)
+ a = RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.knowntype == list
+ assert s.s_item.knowntype == T
+
+
def g(n):
return [0,1,2,n]
More information about the Pypy-commit
mailing list