Skip to content

Commit 2bca5f4

Browse files
[3.12] gh-110938: Fix error messages for indented blocks with functio… (#110990)
[3.12] gh-110938: Fix error messages for indented blocks with functions and classes with generic type parameters (GH-110973) (cherry picked from commit 24e4ec7) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent 8134811 commit 2bca5f4

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

Grammar/python.gram

+3-3
Original file line numberDiff line numberDiff line change
@@ -1369,11 +1369,11 @@ invalid_for_stmt:
13691369
| [ASYNC] a='for' star_targets 'in' star_expressions ':' NEWLINE !INDENT {
13701370
RAISE_INDENTATION_ERROR("expected an indented block after 'for' statement on line %d", a->lineno) }
13711371
invalid_def_raw:
1372-
| [ASYNC] a='def' NAME '(' [params] ')' ['->' expression] ':' NEWLINE !INDENT {
1372+
| [ASYNC] a='def' NAME [type_params] '(' [params] ')' ['->' expression] ':' NEWLINE !INDENT {
13731373
RAISE_INDENTATION_ERROR("expected an indented block after function definition on line %d", a->lineno) }
13741374
invalid_class_def_raw:
1375-
| 'class' NAME ['(' [arguments] ')'] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1376-
| a='class' NAME ['(' [arguments] ')'] ':' NEWLINE !INDENT {
1375+
| 'class' NAME [type_params] ['(' [arguments] ')'] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
1376+
| a='class' NAME [type_params] ['(' [arguments] ')'] ':' NEWLINE !INDENT {
13771377
RAISE_INDENTATION_ERROR("expected an indented block after class definition on line %d", a->lineno) }
13781378

13791379
invalid_double_starred_kvpairs:

Lib/test/test_syntax.py

+10
Original file line numberDiff line numberDiff line change
@@ -1446,11 +1446,21 @@
14461446
Traceback (most recent call last):
14471447
IndentationError: expected an indented block after function definition on line 1
14481448
1449+
>>> def foo[T](x, /, y, *, z=2):
1450+
... pass
1451+
Traceback (most recent call last):
1452+
IndentationError: expected an indented block after function definition on line 1
1453+
14491454
>>> class Blech(A):
14501455
... pass
14511456
Traceback (most recent call last):
14521457
IndentationError: expected an indented block after class definition on line 1
14531458
1459+
>>> class Blech[T](A):
1460+
... pass
1461+
Traceback (most recent call last):
1462+
IndentationError: expected an indented block after class definition on line 1
1463+
14541464
>>> match something:
14551465
... pass
14561466
Traceback (most recent call last):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix error messages for indented blocks with functions and classes with
2+
generic type parameters. Patch by Pablo Galindo

Parser/parser.c

+31-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)