gh-118082: Improve import without names syntax error message (#118083)

This commit is contained in:
Nikita Sobolev 2024-04-23 15:00:52 +03:00 committed by GitHub
parent eb927e9fc8
commit de1f686827
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 219 additions and 149 deletions

View file

@ -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") }