File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1415,11 +1415,11 @@ invalid_import:
14151415 | 'import' token=NEWLINE {
14161416 RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
14171417invalid_dotted_as_name:
1418- | dotted_name 'as' !(NAME (',' | ')' | NEWLINE)) a=expression {
1418+ | dotted_name 'as' !(NAME (',' | ')' | ';' | NEWLINE)) a=expression {
14191419 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a,
14201420 "cannot use %s as import target", _PyPegen_get_expr_name(a)) }
14211421invalid_import_from_as_name:
1422- | NAME 'as' !(NAME (',' | ')' | NEWLINE)) a=expression {
1422+ | NAME 'as' !(NAME (',' | ')' | ';' | NEWLINE)) a=expression {
14231423 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a,
14241424 "cannot use %s as import target", _PyPegen_get_expr_name(a)) }
14251425
Original file line number Diff line number Diff line change 21332133Traceback (most recent call last):
21342134SyntaxError: cannot use subscript as import target
21352135
2136+ # Check that we don't raise a "cannot use name as import target" error
2137+ # if there is an error in an unrelated statement after ';'
2138+
2139+ >>> import a as b; None = 1
2140+ Traceback (most recent call last):
2141+ SyntaxError: cannot assign to None
2142+
2143+ >>> import a, b as c; d = 1; None = 1
2144+ Traceback (most recent call last):
2145+ SyntaxError: cannot assign to None
2146+
2147+ >>> from a import b as c; None = 1
2148+ Traceback (most recent call last):
2149+ SyntaxError: cannot assign to None
2150+
2151+ >>> from a import b, c as d; e = 1; None = 1
2152+ Traceback (most recent call last):
2153+ SyntaxError: cannot assign to None
2154+
21362155# Check that we dont raise the "trailing comma" error if there is more
21372156# input to the left of the valid part that we parsed.
21382157
You can’t perform that action at this time.
0 commit comments