[pypy-svn] r59810 - in pypy/trunk/pypy/annotation: . test
arigo at codespeak.net
arigo at codespeak.net
Sat Nov 8 16:34:24 CET 2008
Author: arigo
Date: Sat Nov 8 16:34:23 2008
New Revision: 59810
Modified:
pypy/trunk/pypy/annotation/test/test_annrpython.py
pypy/trunk/pypy/annotation/unaryop.py
Log:
Test and fix: yet another of those order-dependant issues
shown by "assert s_value.contains(...)" in the annotator.
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 Sat Nov 8 16:34:23 2008
@@ -3105,7 +3105,22 @@
a = self.RPythonAnnotator()
py.test.raises(TooLateForChange, a.build_types, f, [])
-
+
+
+ def test_len_of_empty_list(self):
+ class X:
+ pass
+ def f(n):
+ x = X()
+ x.lst = None
+ if n < 0: # to showcase a failure of the famous "assert contains"
+ return len(x.lst)
+ x.lst = []
+ return len(x.lst)
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [int])
+ assert s.const == 0
+
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 Sat Nov 8 16:34:23 2008
@@ -668,6 +668,14 @@
elif not pbc.can_be_None:
s.const = True
+ def len(pbc):
+ if pbc.isNone():
+ # this None could later be generalized into an empty list,
+ # whose length is the constant 0; so let's tentatively answer 0.
+ return immutablevalue(0)
+ else:
+ return SomeObject() # len() on a pbc? no chance
+
class __extend__(SomeGenericCallable):
def call(self, args):
bookkeeper = getbookkeeper()
More information about the Pypy-commit
mailing list