mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-118082: Improve import
without names syntax error message (#118083)
This commit is contained in:
parent
eb927e9fc8
commit
de1f686827
4 changed files with 219 additions and 149 deletions
|
@ -1299,10 +1299,14 @@ invalid_group:
|
|||
invalid_import:
|
||||
| a='import' ','.dotted_name+ 'from' dotted_name {
|
||||
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }
|
||||
| 'import' token=NEWLINE {
|
||||
RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
|
||||
|
||||
invalid_import_from_targets:
|
||||
| import_from_as_names ',' NEWLINE {
|
||||
RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") }
|
||||
| token=NEWLINE {
|
||||
RAISE_SYNTAX_ERROR_STARTING_FROM(token, "Expected one or more names after 'import'") }
|
||||
|
||||
invalid_compound_stmt:
|
||||
| a='elif' named_expression ':' { RAISE_SYNTAX_ERROR_STARTING_FROM(a, "'elif' must match an if-statement here") }
|
||||
|
|
|
@ -1699,6 +1699,18 @@ SyntaxError: Did you mean to use 'from ... import ...' instead?
|
|||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
>>> from i import
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Expected one or more names after 'import'
|
||||
|
||||
>>> from .. import
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Expected one or more names after 'import'
|
||||
|
||||
>>> import
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Expected one or more names after 'import'
|
||||
|
||||
>>> (): int
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: only single target (not tuple) can be annotated
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Improve :exc:`SyntaxError` message for imports without names, like in
|
||||
``from x import`` and ``import`` cases. It now points
|
||||
out to users that :keyword:`import` expects at least one name after it.
|
349
Parser/parser.c
generated
349
Parser/parser.c
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue