Philip Jenvey avatar Philip Jenvey committed fa91fc5

add a maybe helpful error message

Comments (0)

Files changed (2)

pypy/objspace/std/test/test_unicodeobject.py

         assert 'ab'.startswith('b', 1) is True
         assert 'abc'.startswith('bc', 1, 2) is False
         assert 'abc'.startswith('c', -1, 4) is True
+        try:
+            'hello'.startswith(['o'])
+        except TypeError as e:
+            msg = str(e)
+            assert 'str' in msg
+            assert 'tuple' in msg
+        else:
+            assert False, 'Expected TypeError'
 
     def test_startswith_tuples(self):
         assert 'hello'.startswith(('he', 'ha'))
         assert 'abc'.endswith('bc', 1) is True
         assert 'abc'.endswith('bc', 2) is False
         assert 'abc'.endswith('b', -3, -1) is True
+        try:
+            'hello'.endswith(['o'])
+        except TypeError as e:
+            msg = str(e)
+            assert 'str' in msg
+            assert 'tuple' in msg
+        else:
+            assert False, 'Expected TypeError'
 
     def test_endswith_tuple(self):
         assert not 'hello'.endswith(('he', 'ha'))

pypy/objspace/std/unicodeobject.py

             space, len(self), w_start, w_end, upper_bound)
     return (self, start, end)
 
+def unicode_endswith__Unicode_ANY_ANY_ANY(space, w_self, w_substr, w_start, w_end):
+    typename = space.type(w_substr).getname(space)
+    msg = "endswith first arg must be str or a tuple of str, not %s" % typename
+    raise OperationError(space.w_TypeError, space.wrap(msg))
+
 def unicode_endswith__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end):
     self, start, end = _convert_idx_params(space, w_self,
                                                    w_start, w_end, True)
     return space.newbool(stringendswith(self, w_substr._value, start, end))
 
+def unicode_startswith__Unicode_ANY_ANY_ANY(space, w_self, w_substr, w_start, w_end):
+    typename = space.type(w_substr).getname(space)
+    msg = ("startswith first arg must be str or a tuple of str, not %s" %
+           typename)
+    raise OperationError(space.w_TypeError, space.wrap(msg))
+
 def unicode_startswith__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end):
     self, start, end = _convert_idx_params(space, w_self, w_start, w_end, True)
     # XXX this stuff can be waaay better for ootypebased backends if
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.