8000 gh-110938: Fix error messages for indented blocks with functions and … · python/cpython@24e4ec7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 24e4ec7

Browse files
authored
gh-110938: Fix error messages for indented blocks with functions and classes with generic type parameters (#110973)
1 parent be5e8a0 commit 24e4ec7

File tree

4 files changed

+46
-22
lines changed
  • Parser
  • 4 files changed

    +46
    -22
    lines changed

    Grammar/python.gram

    Lines changed: 3 additions & 3 deletions
    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

    Lines changed: 10 additions & 0 deletions
    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):
    Lines changed: 2 additions & 0 deletions
    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

    Lines changed: 31 additions & 19 deletions
    Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

    0 commit comments

    Comments
     (0)
    0