Skip to content

Unhelpful SyntaxError with unclosed call before colon#94034

@brandtbucher

Description

@brandtbucher

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:

>>>forfooinbar(baz: File"<stdin>", line1forfooinbar(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>", line1forfooinbar(baz: ^SyntaxError: invalidsyntax

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

>>>bar(baz: File"<stdin>", line1forfooinbar(baz: ^SyntaxError: '('wasneverclosed

@pablogsal

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only security fixes3.11only security fixes3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions