cpython: 3ceeccbc2c3b (original) (raw)
Mercurial > cpython
changeset 69562:3ceeccbc2c3b 2.7
#6780: fix starts/endswith error message to mention that tuples are accepted too. [#6780]
Ezio Melotti | |
---|---|
date | Tue, 26 Apr 2011 05:12:51 +0300 |
parents | 48758cd0769b |
children | a3b4887edba4 |
files | Lib/test/test_str.py Lib/test/test_unicode.py Misc/NEWS Objects/stringobject.c Objects/unicodeobject.c |
diffstat | 5 files changed, 46 insertions(+), 6 deletions(-)[+] [-] Lib/test/test_str.py 13 Lib/test/test_unicode.py 11 Misc/NEWS 3 Objects/stringobject.c 12 Objects/unicodeobject.c 13 |
line wrap: on
line diff
--- a/Lib/test/test_str.py +++ b/Lib/test/test_str.py @@ -414,7 +414,18 @@ class StrTest( self.assertEqual('Andr\202 x'.decode('ascii', 'replace'), 'Andr\202 x'.decode(encoding='ascii', errors='replace')) -
- def test_startswith_endswith_errors(self):
with self.assertRaises(UnicodeDecodeError):[](#l1.9)
'\xff'.startswith(u'x')[](#l1.10)
with self.assertRaises(UnicodeDecodeError):[](#l1.11)
'\xff'.endswith(u'x')[](#l1.12)
for meth in ('foo'.startswith, 'foo'.endswith):[](#l1.13)
with self.assertRaises(TypeError) as cm:[](#l1.14)
meth(['f'])[](#l1.15)
exc = str(cm.exception)[](#l1.16)
self.assertIn('unicode', exc)[](#l1.17)
self.assertIn('str', exc)[](#l1.18)
self.assertIn('tuple', exc)[](#l1.19)
def test_main(): test_support.run_unittest(StrTest)
--- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -442,6 +442,17 @@ class UnicodeTest( return u'\u1234' self.assertEqual('%s' % Wrapper(), u'\u1234')
- def test_startswith_endswith_errors(self):
for meth in (u'foo'.startswith, u'foo'.endswith):[](#l2.8)
with self.assertRaises(UnicodeDecodeError):[](#l2.9)
meth('\xff')[](#l2.10)
with self.assertRaises(TypeError) as cm:[](#l2.11)
meth(['f'])[](#l2.12)
exc = str(cm.exception)[](#l2.13)
self.assertIn('unicode', exc)[](#l2.14)
self.assertIn('str', exc)[](#l2.15)
self.assertIn('tuple', exc)[](#l2.16)
+ @test_support.run_with_locale('LC_ALL', 'de_DE', 'fr_FR') def test_format_float(self): # should not format with a comma, but always with C locale
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,9 @@ What's New in Python 2.7.2? Core and Builtins ----------------- +- Issue #6780: fix starts/endswith error message to mention that tuples are
- Issue #5057: fix a bug in the peepholer that led to non-portable pyc files between narrow and wide builds while optimizing BINARY_SUBSCR on non-BMP chars (e.g. u"\U00012345"[0]).
--- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -2918,8 +2918,12 @@ string_startswith(PyStringObject *self, Py_RETURN_FALSE; } result = _string_tailmatch(self, subobj, start, end, -1);
- if (result == -1) {
if (PyErr_ExceptionMatches(PyExc_TypeError))[](#l4.9)
PyErr_Format(PyExc_TypeError, "startswith first arg must be str, "[](#l4.10)
"unicode, or tuple, not %s", Py_TYPE(subobj)->tp_name);[](#l4.11) return NULL;[](#l4.12)
- } else return PyBool_FromLong(result);
} @@ -2958,8 +2962,12 @@ string_endswith(PyStringObject *self, Py Py_RETURN_FALSE; } result = _string_tailmatch(self, subobj, start, end, +1);
- if (result == -1) {
if (PyErr_ExceptionMatches(PyExc_TypeError))[](#l4.23)
PyErr_Format(PyExc_TypeError, "endswith first arg must be str, "[](#l4.24)
"unicode, or tuple, not %s", Py_TYPE(subobj)->tp_name);[](#l4.25) return NULL;[](#l4.26)
- } else return PyBool_FromLong(result);
--- 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 (PyErr_ExceptionMatches(PyExc_TypeError))[](#l5.9)
PyErr_Format(PyExc_TypeError, "startswith first arg must be str, "[](#l5.10)
"unicode, or tuple, not %s", Py_TYPE(subobj)->tp_name);[](#l5.11) return NULL;[](#l5.12)
- } 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);