File tree Expand file tree Collapse file tree 3 files changed +508
-483
lines changed
Expand file tree Collapse file tree 3 files changed +508
-483
lines changed Original file line number Diff line number Diff line change @@ -1434,13 +1434,13 @@ invalid_import:
14341434invalid_dotted_as_name:
14351435 | a=dotted_name b=['as' NAME] c=dotted_name ('as' | ',' | ')' | ';' | NEWLINE) {
14361436 RAISE_SYNTAX_ERROR_KNOWN_RANGE(b ? (expr_ty) b : a, c, "expected comma between import clauses") }
1437- | dotted_name 'as' !(NAME (',' | ')' | ';' | NEWLINE)) a=expression {
1437+ | dotted_name 'as' !(NAME (',' | ')' | ';' | NEWLINE)) a=expression (',' | ')' | ';' | NEWLINE) {
14381438 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a,
14391439 "cannot use %s as import target", _PyPegen_get_expr_name(a)) }
14401440invalid_import_from_as_name:
14411441 | [NAME 'as'] a=NAME b=NAME ('as' | ',' | ')' | ';' | NEWLINE) {
14421442 RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected comma between import clauses") }
1443- | NAME 'as' !(NAME (',' | ')' | ';' | NEWLINE)) a=expression {
1443+ | NAME 'as' !(NAME (',' | ')' | ';' | NEWLINE)) a=expression (',' | ')' | ';' | NEWLINE) {
14441444 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a,
14451445 "cannot use %s as import target", _PyPegen_get_expr_name(a)) }
14461446
Original file line number Diff line number Diff line change 22062206Traceback (most recent call last):
22072207SyntaxError: cannot assign to None
22082208
2209+ # Check that we don't raise a "cannot use name as import target" error
2210+ # when there's a syntax error after the import target.
2211+
2212+ >>> import a as b(-)
2213+ Traceback (most recent call last):
2214+ SyntaxError: invalid syntax
2215+
2216+ >>> import a as b None
2217+ Traceback (most recent call last):
2218+ SyntaxError: invalid syntax
2219+
2220+ >>> import a as b as c
2221+ Traceback (most recent call last):
2222+ SyntaxError: invalid syntax
2223+
2224+ >>> from x import a as b None
2225+ Traceback (most recent call last):
2226+ SyntaxError: invalid syntax
2227+
22092228# Check that we dont raise the "trailing comma" error if there is more
22102229# input to the left of the valid part that we parsed.
22112230
You can’t perform that action at this time.
0 commit comments