8000 invalid_def_raw and invalid_class_def_raw rules do not account for type parameters · Issue #110938 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

invalid_def_raw and invalid_class_def_raw rules do not account for type parameters #110938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MatthieuDartiailh opened this issue Oct 16, 2023 · 3 comments · Fixed by #110973
Closed
Assignees
Labels
3.12 only security fixes 3.13 bugs and security fixes topic-parser topic-typing type-bug An unexpected behavior, bug, or error

Comments

@MatthieuDartiailh
Copy link
Contributor
MatthieuDartiailh commented Oct 16, 2023

Bug report

Bug description:

The rules which are affected are here:

invalid_def_raw:

Typically I believe they should read

invalid_def_raw:
    | ['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 [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) }

to allow proper error reporting if the definition uses type parameters.

CPython versions tested on:

3.12

Operating systems tested on:

No response

Linked PRs

@MatthieuDartiailh MatthieuDartiailh added the type-bug An unexpected behavior, bug, or error label Oct 16, 2023
@Eclips4
Copy link
Member
Eclips4 commented Oct 16, 2023

cc @pablogsal @lysnikolaou and @JelleZijlstra as author of implementation of PEP 695

@pablogsal
Copy link
Member

Will make a pr today

@Eclips4 Eclips4 added 3.12 only security fixes 3.13 bugs and security fixes labels Oct 16, 2023
pablogsal added a commit to pablogsal/cpython that referenced this issue Oct 17, 2023
…s and classes with generic type parameters

Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
pablogsal added a commit that referenced this issue Oct 17, 2023
@sobolevn
Copy link
Member

Sorry for being late with the review, but there are several test cases that are missing from @pablogsal's PR. I've opened a new one to address this case:

  • before:
>>> class A[T]
  File "<stdin>", line 1
    class A[T]
              ^
SyntaxError: invalid syntax
>>> class A[T]()
  File "<stdin>", line 1
    class A[T]()
                ^
SyntaxError: invalid syntax
  • after:
>>> class A[T]
  File "<stdin>", line 1
    class A[T]
              ^
SyntaxError: expected ':'
>>> class A[T]()
  File "<stdin>", line 1
    class A[T]()
                ^
SyntaxError: expected ':'

It is fixed, but not tested 👍

@sobolevn sobolevn reopened this Oct 17, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 17, 2023
JelleZijlstra pushed a commit to JelleZijlstra/cpython that referenced this issue Oct 17, 2023
…unctions and classes with generic type parameters (pythonGH-110973)

(cherry picked from commit 24e4ec7)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 18, 2023
…onGH-110986)

(cherry picked from commit 220bcc9)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
JelleZijlstra added a commit that referenced this issue Oct 18, 2023
#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>
JelleZijlstra pushed a commit that referenced this issue Oct 18, 2023
…110986) (#111023)

gh-110938: More syntax tests for PEP695 funcs and classes (GH-110986)
(cherry picked from commit 220bcc9)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes 3.13 bugs and security fixes topic-parser topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
5 participants
0