bpo-44110: Improve string's __getitem__ error message by miguendes · Pull Request #26042 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Lib/test/string_tests.py
4 changes: 3 additions & 1 deletion Lib/test/test_userstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ def checkequal(self, result, object, methodname, *args, **kwargs):
realresult
)

def checkraises(self, exc, obj, methodname, *args):
def checkraises(self, exc, obj, methodname, *args, expected_msg=None):
obj = self.fixtype(obj)
# we don't fix the arguments, because UserString can't cope with it
with self.assertRaises(exc) as cm:
getattr(obj, methodname)(*args)
self.assertNotEqual(str(cm.exception), '')
if expected_msg is not None:
self.assertEqual(str(cm.exception), expected_msg)

def checkcall(self, object, methodname, *args):
object = self.fixtype(object)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve :func:`str.__getitem__` error message
3 changes: 2 additions & 1 deletion Objects/unicodeobject.c