Author: Armin Rigo <[email protected]>
Branch: stdlib-2.7.13
Changeset: r89156:b558a727875c
Date: 2016-12-18 18:40 +0100
http://bitbucket.org/pypy/pypy/changeset/b558a727875c/
Log: Check early that we get a list of strings
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -350,8 +350,13 @@
# bit artificial code but important to not just unwrap w_fromlist
# to get a better trace. if it is unwrapped, the immutability of the
# tuple is lost
+ length = space.len_w(w_fromlist)
+ for i in range(length):
+ w_name = space.getitem(w_fromlist, space.wrap(i))
+ if not space.isinstance_w(w_name, space.w_str):
+ raise oefmt(space.w_TypeError,
+ "'fromlist' must be a list of strings, got %T", w_name)
if w_path is not None:
- length = space.len_w(w_fromlist)
if length == 1 and space.eq_w(
space.getitem(w_fromlist, space.wrap(0)),
space.wrap('*')):
diff --git a/pypy/module/imp/test/test_import.py
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -351,6 +351,9 @@
o = __import__('sys', [], [], ['']) # CPython accepts this
assert sys == o
+ def test_import_fromlist_must_not_contain_unicodes(self):
+ raises(TypeError, __import__, 'encodings', None, None, [u'xxx'])
+
def test_import_relative_back_to_absolute2(self):
from pkg import abs_x_y
import sys
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit