micropython/tests/import/import_star_error.py
Petr Viktorin 25a9bccdee 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.
2019-10-04 16:46:47 +10:00

14 lines
328 B
Python

# 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')