Skip to content

Unhelpful SyntaxError with unclosed call before colon #94034

Closed as not planned
Closed as not planned

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:

>>> 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

Activity

  1. added
    type-feature
    3.11
    3.10 (EOL)
    3.12
    on Jun 20, 2022
  2. pablogsal commented on Jun 20, 2022

    @pablogsal
    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 :)

  3. added
    interpreter-core
    on Jun 20, 2022
  4. brandtbucher commented on Jun 20, 2022

    @brandtbucher
    MemberAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)3.113.12interpreter-coretype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions