File tree Expand file tree Collapse file tree 4 files changed +219
-149
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 4 files changed +219
-149
lines changed Original file line number Diff line number Diff line change @@ -1299,10 +1299,14 @@ invalid_group:
1299
1299
invalid_import:
1300
1300
| a='import' ','.dotted_name+ 'from' dotted_name {
1301
1301
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }
1302
+ | 'import' token=NEWLINE {
1303
+ RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
1302
1304
1303
1305
invalid_import_from_targets:
1304
1306
| import_from_as_names ',' NEWLINE {
1305
1307
RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") }
1308
+ | token=NEWLINE {
1309
+ RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
1306
1310
1307
1311
invalid_compound_stmt:
1308
1312
| a='elif' named_expression ':' { RAISE_SYNTAX_ERROR_STARTING_FROM(a, "'elif' must match an if-statement here") }
Original file line number Diff line number Diff line change 1699
1699
Traceback (most recent call last):
1700
1700
SyntaxError: invalid syntax
1701
1701
1702
+ >>> from i import
1703
+ Traceback (most recent call last):
1704
+ SyntaxError: Expected one or more names after 'import'
1705
+
1706
+ >>> from .. import
1707
+ Traceback (most recent call last):
1708
+ SyntaxError: Expected one or more names after 'import'
1709
+
1710
+ >>> import
1711
+ Traceback (most recent call last):
1712
+ SyntaxError: Expected one or more names after 'import'
1713
+
1702
1714
>>> (): int
1703
1715
Traceback (most recent call last):
1704
1716
SyntaxError: only single target (not tuple) can be annotated
Original file line number Diff line number Diff line change
1
+ Improve :exc: `SyntaxError ` message for imports without names, like in
2
+ ``from x import `` and ``import `` cases. It now points
3
+ out to users that :keyword: `import ` expects at least one name after it.
You can’t perform that action at this time.
0 commit comments