Skip to content
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

Unhelpful SyntaxError with unclosed call before colon #94034

Closed
brandtbucher opened this issue Jun 20, 2022 · 2 comments
Closed

Unhelpful SyntaxError with unclosed call before colon #94034

brandtbucher opened this issue Jun 20, 2022 · 2 comments
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@brandtbucher
Copy link
Member

Ran into this today. If you forget to close parentheses as part of a call in the header of a for, with, or class statement (maybe others too?), the SyntaxError seems to indicate that you forgot a colon:

>>> for foo in bar(baz:
  File "<stdin>", line 1
    for foo in bar(baz:
                  ^
SyntaxError: expected ':'

It's not wrong, but could probably be improved. I personally find the pre-3.10 behavior more helpful:

>>> bar(baz:
  File "<stdin>", line 1
    for foo in bar(baz:
                      ^
SyntaxError: invalid syntax

Even better, though, would be a "smarter" error message like the existing ones we have for unclosed parentheses:

>>> bar(baz:
  File "<stdin>", line 1
    for foo in bar(baz:
                  ^
SyntaxError: '(' was never closed

@pablogsal

@brandtbucher brandtbucher added type-feature A feature request or enhancement 3.11 only security fixes 3.10 only security fixes 3.12 bugs and security fixes labels Jun 20, 2022
@pablogsal
Copy link
Member

I think this will be fixed by #92894 (comment). @brandtbucher can you check (I'm away from the keyboard right now)? Otherwise I will do it later today :)

@brandtbucher brandtbucher added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jun 20, 2022
@brandtbucher
Copy link
Member Author

Looks like it might be. At any rate, I'll close this as a duplicate of #92858.

@brandtbucher brandtbucher closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants