summaryrefslogtreecommitdiff
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorEzio Melotti <none@none>2011-04-26 05:12:51 +0300
committerEzio Melotti <none@none>2011-04-26 05:12:51 +0300
commite3685f6b1b27bf089a40a12492f952dda5ff3ea2 (patch)
treec203d4df92443193797fd04fe93508711c280b92 /Objects/unicodeobject.c
parenta0895db2e1e94a7a2dfba4f75475975720aae224 (diff)
downloadcpython-git-e3685f6b1b27bf089a40a12492f952dda5ff3ea2.tar.gz
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 4098fb38ae..b2332a5360 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -7666,8 +7666,12 @@ unicode_startswith(PyUnicodeObject *self,
Py_RETURN_FALSE;
}
substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj);
- if (substring == NULL)
+ if (substring == NULL) {
+ if (PyErr_ExceptionMatches(PyExc_TypeError))
+ PyErr_Format(PyExc_TypeError, "startswith first arg must be str, "
+ "unicode, or tuple, not %s", Py_TYPE(subobj)->tp_name);
return NULL;
+ }
result = tailmatch(self, substring, start, end, -1);
Py_DECREF(substring);
return PyBool_FromLong(result);
@@ -7710,9 +7714,12 @@ unicode_endswith(PyUnicodeObject *self,
Py_RETURN_FALSE;
}
substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj);
- if (substring == NULL)
+ if (substring == NULL) {
+ if (PyErr_ExceptionMatches(PyExc_TypeError))
+ PyErr_Format(PyExc_TypeError, "endswith first arg must be str, "
+ "unicode, or tuple, not %s", Py_TYPE(subobj)->tp_name);
return NULL;
-
+ }
result = tailmatch(self, substring, start, end, +1);
Py_DECREF(substring);
return PyBool_FromLong(result);