[pypy-svn] r68115 - in pypy/trunk/pypy/annotation: . test
pedronis at codespeak.net
pedronis at codespeak.net
Thu Oct 1 19:04:24 CEST 2009
Author: pedronis
Date: Thu Oct 1 19:04:23 2009
New Revision: 68115
Modified:
pypy/trunk/pypy/annotation/test/test_annrpython.py
pypy/trunk/pypy/annotation/unaryop.py
Log:
(cfbolz, pedronis) op_contains of a dict should annotate SomeBool(const=False) as long as it is considered empty
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 Thu Oct 1 19:04:23 2009
@@ -3196,6 +3196,33 @@
s = a.build_types(f, [])
assert s.knowntype == int
+ def test_contains_of_empty_dict(self):
+ class A(object):
+ def meth(self):
+ return 1
+
+ def g(x, y):
+ d1 = {}
+ for i in range(y):
+ if x in d1:
+ return d1[x].meth()
+ d1[i+1] = A()
+ return 0
+
+ a = self.RPythonAnnotator()
+ s = a.build_types(g, [int, int])
+ assert s.knowntype is int
+
+ def f(x):
+ d0 = {}
+ if x in d0:
+ d0[x].meth()
+ return x+1
+
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [int])
+ assert s.knowntype is int
+
def g(n):
return [0,1,2,n]
Modified: pypy/trunk/pypy/annotation/unaryop.py
==============================================================================
--- pypy/trunk/pypy/annotation/unaryop.py (original)
+++ pypy/trunk/pypy/annotation/unaryop.py Thu Oct 1 19:04:23 2009
@@ -375,10 +375,14 @@
class __extend__(SomeDict):
- def len(dct):
+ def _is_empty(dct):
s_key = dct.dictdef.read_key()
s_value = dct.dictdef.read_value()
- if isinstance(s_key, SomeImpossibleValue) or isinstance(s_value, SomeImpossibleValue):
+ return (isinstance(s_key, SomeImpossibleValue) or
+ isinstance(s_value, SomeImpossibleValue))
+
+ def len(dct):
+ if dct._is_empty():
return immutablevalue(0)
return SomeObject.len(dct)
@@ -443,6 +447,10 @@
def op_contains(dct, s_element):
dct.dictdef.generalize_key(s_element)
+ if dct._is_empty():
+ s_bool = SomeBool()
+ s_bool.const = False
+ return s_bool
return s_Bool
op_contains.can_only_throw = _can_only_throw
More information about the Pypy-commit
mailing list