diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cmdline/cmd_showbc.py | 5 | ||||
-rw-r--r-- | tests/cmdline/cmd_showbc.py.exp | 12 | ||||
-rw-r--r-- | tests/import/import_star_error.py | 13 |
3 files changed, 23 insertions, 7 deletions
diff --git a/tests/cmdline/cmd_showbc.py b/tests/cmdline/cmd_showbc.py index 916228356..f30b39ee1 100644 --- a/tests/cmdline/cmd_showbc.py +++ b/tests/cmdline/cmd_showbc.py @@ -115,7 +115,7 @@ def f(): # import import a from a import b - from a import * + #from sys import * # tested at module scope # raise raise @@ -154,3 +154,6 @@ del Class # load super method def f(self): super().f() + +# import * (needs to be in module scope) +from sys import * diff --git a/tests/cmdline/cmd_showbc.py.exp b/tests/cmdline/cmd_showbc.py.exp index b0a9016c5..4d90ae22c 100644 --- a/tests/cmdline/cmd_showbc.py.exp +++ b/tests/cmdline/cmd_showbc.py.exp @@ -7,7 +7,7 @@ arg names: (N_EXC_STACK 0) bc=0 line=1 ######## - bc=\\d\+ line=155 + bc=\\d\+ line=159 00 MAKE_FUNCTION \.\+ \\d\+ STORE_NAME f \\d\+ MAKE_FUNCTION \.\+ @@ -27,6 +27,11 @@ arg names: \\d\+ DELETE_NAME Class \\d\+ MAKE_FUNCTION \.\+ \\d\+ STORE_NAME f +\\d\+ LOAD_CONST_SMALL_INT 0 +\\d\+ LOAD_CONST_STRING '*' +\\d\+ BUILD_TUPLE 1 +\\d\+ IMPORT_NAME 'sys' +\\d\+ IMPORT_STAR \\d\+ LOAD_CONST_NONE \\d\+ RETURN_VALUE File cmdline/cmd_showbc.py, code block 'f' (descriptor: \.\+, bytecode @\.\+ bytes) @@ -300,11 +305,6 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): \\d\+ IMPORT_FROM 'b' \\d\+ STORE_DEREF 14 \\d\+ POP_TOP -\\d\+ LOAD_CONST_SMALL_INT 0 -\\d\+ LOAD_CONST_STRING '*' -\\d\+ BUILD_TUPLE 1 -\\d\+ IMPORT_NAME 'a' -\\d\+ IMPORT_STAR \\d\+ RAISE_LAST \\d\+ LOAD_CONST_SMALL_INT 1 \\d\+ RAISE_OBJ 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') |