Skip to content

Conversation

@sobolevn
Copy link
Member

@sobolevn sobolevn commented Oct 12, 2024

This does not fix 100% of cases, but makes the situation better. What is not covered? For example:

>>> def some[call()](): ...
  File "<python-input-0>", line 1
    def some[call()](): ...
            ^
SyntaxError: expected '('

This happens because of how rules detect top-level type_params. I don't think that there's a clean way to handle this.

However, my patch also fixes a lot of possible corner cases.

…e-125326.LCH9st.rst

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
…e-125326.LCH9st.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct but I'm not sure the special error messages are worth it; I haven't personally seen evidence from users who saw these errors and were confused. Adding more special-case error messages to the grammar increases the complexity of the system. I'll leave that to the parser maintainers to decide.

| '[' token=']' {
RAISE_SYNTAX_ERROR_STARTING_FROM(
token,
"Type parameter list cannot be empty")}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Type parameter list cannot be empty")}
"type parameter list cannot be empty")}

We're not completely consistent but most syntax error messages are lowercase.

@sobolevn
Copy link
Member Author

Yeah, I kinda agree that this PR is not ideal, as I said in the first post.
Since it does not really cover all possible cases.

@sobolevn sobolevn closed this Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants