25a9bccdee
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.
14 lines
328 B
Python
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')
|