Ronan Lamy committed 5757d72

Give understandable error when attempting to use str.format()

Comments (0)

Files changed (2)


         py.test.raises(annmodel.AnnotatorError, "a.build_types(f, [int, int])")
         a.build_types(f, [annmodel.SomeInteger(nonneg=True),
     def test_setslice(self):
         def f():
             a.build_types(f, [str])
         assert ("Cannot prove that the object is callable" in exc.value.msg)
+    def test_str_format_error(self):
+        def f(s, x):
+            return s.format(x)
+        a = self.RPythonAnnotator()
+        with py.test.raises(annmodel.AnnotatorError) as exc:
+            a.build_types(f, [str, str])
+        assert ("format() is not RPython" in exc.value.msg)
 def g(n):
     return [0, 1, 2, n]


             return SomeObject.op_contains(str, s_element)
     op_contains.can_only_throw = []
+    def method_format(self, *args):
+        raise AnnotatorError("Method format() is not RPython")
 class __extend__(SomeByteArray):
     def getslice(ba, s_start, s_stop):