Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r79460:77d8c602142b
Date: 2015-09-05 13:13 +0200
http://bitbucket.org/pypy/pypy/changeset/77d8c602142b/

Log:    Test and fix for rare annotation issue

diff --git a/rpython/annotator/test/test_annrpython.py 
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -4492,6 +4492,15 @@
         with py.test.raises(annmodel.AnnotatorError):
             a.build_types(f, [int])
 
+    def test_dict_can_be_none_ordering_issue(self):
+        def g(d):
+            return 42 in d
+        def f(n):
+            g(None)
+            g({})
+        a = self.RPythonAnnotator()
+        a.build_types(f, [int])
+
 
 def g(n):
     return [0, 1, 2, n]
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -49,6 +49,16 @@
     return s_Bool
 contains_SomeObject.can_only_throw = []
 
+@op.contains.register(SomeNone)
+def contains_SomeNone(annotator, obj, element):
+    # return False here for the case "... in None", because it can be later
+    # generalized to "... in d" where d is either None or the empty dict
+    # (which would also return the constant False)
+    s_bool = SomeBool()
+    s_bool.const = False
+    return s_bool
+contains_SomeNone.can_only_throw = []
+
 @op.simple_call.register(SomeObject)
 def simple_call_SomeObject(annotator, func, *args):
     return annotator.annotation(func).call(
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to