summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2024-04-23 12:00:52 (GMT)
committerGitHub <noreply@github.com>2024-04-23 12:00:52 (GMT)
commitde1f6868270d31f56c388ef416daacd35feb152d (patch)
tree65b30c6d5b2cd0d8acf75fc9150decac082c0852 /Grammar
parenteb927e9fc823de9539fcb82c9ea9d055462eb04a (diff)
downloadcpython-de1f6868270d31f56c388ef416daacd35feb152d.zip
cpython-de1f6868270d31f56c388ef416daacd35feb152d.tar.gz
cpython-de1f6868270d31f56c388ef416daacd35feb152d.tar.bz2
gh-118082: Improve `import` without names syntax error message (#118083)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram4
1 files changed, 4 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 9564abf..11438e5 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -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") }