mirror of https://github.com/python/cpython
gh-118082: Improve `import` without names syntax error message (#118083)
This commit is contained in:
parent
eb927e9fc8
commit
de1f686827
|
@ -1299,10 +1299,14 @@ invalid_group:
|
||||||
invalid_import:
|
invalid_import:
|
||||||
| a='import' ','.dotted_name+ 'from' dotted_name {
|
| a='import' ','.dotted_name+ 'from' dotted_name {
|
||||||
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }
|
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:
|
invalid_import_from_targets:
|
||||||
| import_from_as_names ',' NEWLINE {
|
| import_from_as_names ',' NEWLINE {
|
||||||
RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") }
|
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:
|
invalid_compound_stmt:
|
||||||
| a='elif' named_expression ':' { RAISE_SYNTAX_ERROR_STARTING_FROM(a, "'elif' must match an if-statement here") }
|
| 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):
|
Traceback (most recent call last):
|
||||||
SyntaxError: invalid syntax
|
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
|
>>> (): int
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
SyntaxError: only single target (not tuple) can be annotated
|
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.
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue