aboutsummaryrefslogtreecommitdiff
path: root/tests/import
diff options
context:
space:
mode:
authorPetr Viktorin2019-09-20 09:16:34 +0200
committerDamien George2019-10-04 16:46:47 +1000
commit25a9bccdee2fe830046c1c1a0220ca7706597202 (patch)
tree69e2b808f5f523964dd4d71257dc4e9e60f309c4 /tests/import
parent26e90a051415629796efbec59f1d653b46e43aea (diff)
py/compile: Disallow 'import *' outside module level.
This check follows CPython's behaviour, because 'import *' always populates the globals with the imported names, not locals. Since it's safe to do this (doesn't lead to a crash or undefined behaviour) the check is only enabled for MICROPY_CPYTHON_COMPAT. Fixes issue #5121.
Diffstat (limited to 'tests/import')
-rw-r--r--tests/import/import_star_error.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/import/import_star_error.py b/tests/import/import_star_error.py
new file mode 100644
index 000000000..17e237b8c
--- /dev/null
+++ b/tests/import/import_star_error.py
@@ -0,0 +1,13 @@
+# test errors with import *
+
+# 'import *' is not allowed in function scope
+try:
+ exec('def foo(): from x import *')
+except SyntaxError as er:
+ print('function', 'SyntaxError')
+
+# 'import *' is not allowed in class scope
+try:
+ exec('class C: from x import *')
+except SyntaxError as er:
+ print('class', 'SyntaxError')