Skip to content

Commit

Permalink
gh-110938: Fix error messages for indented blocks with functions and …
Browse files Browse the repository at this point in the history
…classes with generic type parameters (#110973)
  • Loading branch information
pablogsal authored Oct 17, 2023
1 parent be5e8a0 commit 24e4ec7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1369,11 +1369,11 @@ invalid_for_stmt:
| ['async'] a='for' star_targets 'in' star_expressions ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after 'for' statement on line %d", a->lineno) }
invalid_def_raw:
| ['async'] a='def' NAME '(' [params] ')' ['->' expression] ':' NEWLINE !INDENT {
| ['async'] a='def' NAME [type_params] '(' [params] ')' ['->' expression] ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after function definition on line %d", a->lineno) }
invalid_class_def_raw:
| 'class' NAME ['(' [arguments] ')'] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| a='class' NAME ['(' [arguments] ')'] ':' NEWLINE !INDENT {
| 'class' NAME [type_params] ['(' [arguments] ')'] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| a='class' NAME [type_params] ['(' [arguments] ')'] ':' NEWLINE !INDENT {
RAISE_INDENTATION_ERROR("expected an indented block after class definition on line %d", a->lineno) }

invalid_double_starred_kvpairs:
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,11 +1446,21 @@
Traceback (most recent call last):
IndentationError: expected an indented block after function definition on line 1
>>> def foo[T](x, /, y, *, z=2):
... pass
Traceback (most recent call last):
IndentationError: expected an indented block after function definition on line 1
>>> class Blech(A):
... pass
Traceback (most recent call last):
IndentationError: expected an indented block after class definition on line 1
>>> class Blech[T](A):
... pass
Traceback (most recent call last):
IndentationError: expected an indented block after class definition on line 1
>>> match something:
... pass
Traceback (most recent call last):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix error messages for indented blocks with functions and classes with
generic type parameters. Patch by Pablo Galindo
50 changes: 31 additions & 19 deletions Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24e4ec7

Please sign in to comment.