[issue21720] "TypeError: Item in ``from list'' not a string" message
Berker Peksag
report at bugs.python.org
Fri Aug 29 02:05:03 CEST 2014
Berker Peksag added the comment:
Thanks for the patch, David!
+ def test_fromlist_error_messages(self):
+ # Test for issue #21720: fromlist unicode error messages
+ try:
+ __import__('encodings', fromlist=[u'aliases'])
+ except TypeError as exc:
+ self.assertIn("must be str, not unicode", str(exc))
You could use assertRaises here:
with self.assertRaises(TypeError) as cm:
# ...
self.assertIn('foo', str(cm.exception))
+ if (PyUnicode_Check(item)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Item in ``from list'' must be str, not unicode");
+ Py_DECREF(item);
+ return 0;
+ }
I think it would be better to improve the error message in Python/import.c:
http://hg.python.org/cpython/file/2.7/Python/import.c#l2571
So you can safely remove this check.
----------
stage: needs patch -> patch review
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21720>
_______________________________________
More information about the Python-bugs-list
mailing list