Ezio Melotti <ezio.melo...@gmail.com> added the comment: In the examples you used byte strings for Py2 and Unicode strings for Py3. On Py3 the same example with byte strings gives an error similar to the one raised by Py2:
>>> b"foo".startswith([b"fo"]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: expected an object with the buffer interface (vs. Py2's expected a character buffer object) The error raised by Py2 with Unicode strings is more or less the same of Py3 too: >>> u"foo".startswith([u"fo", u"df"]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: coercing to Unicode: need string or buffer, list found (vs. Py3's Can't convert 'list' object to str implicitly) If I understood correctly the C code in /Objects/unicodeobject.c, this is because startswith checks if the 'prefix' is a tuple and, if not, it assumes that is a Unicode string. The 'prefix' is then converted to Unicode by PyUnicode_FromObject and if it's a list or some other object the error "Can't convert 'list' object to str implicitly" / "coercing to Unicode: need string or buffer, list found" is raised. I agree that a more explicit error message would be better, something like: "'prefix' must be a character buffer object or a tuple, not 'list'". > Aside: why not try to convert 'list' object to tuple? If the support for lists is added, it should probably be extended to all the iterables, but strings are iterables too, so that will create some problem. It could be checked if 'prefix' is a string and if not assume that is an iterable of strings, but I don't know if it's worth doing it. ---------- components: +Interpreter Core -Library (Lib) nosy: +ezio.melotti priority: -> normal _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6780> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com