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

Wrong syntax error hint when spurious colon present in function keyword comprehension assignment #88334

Closed
gerritholl mannequin opened this issue May 18, 2021 · 3 comments
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@gerritholl
Copy link
Mannequin

gerritholl mannequin commented May 18, 2021

BPO 44168
Nosy @gerritholl, @lysnikolaou, @pablogsal, @miss-islington
PRs
  • bpo-44168: Fix error message in the parser for keyword arguments for invalid expressions #26210
  • [3.10] bpo-44168: Fix error message in the parser for keyword arguments for invalid expressions (GH-26210) #26247
  • [3.9] bpo-44168: Fix error message in the parser for keyword arguments for invalid expressions (GH-26210). #26250
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-05-19.18:13:27.800>
    created_at = <Date 2021-05-18.09:49:58.120>
    labels = ['interpreter-core', '3.9']
    title = 'Wrong syntax error hint when spurious colon present in function keyword comprehension assignment'
    updated_at = <Date 2021-05-19.18:28:35.119>
    user = 'https://github.com/gerritholl'

    bugs.python.org fields:

    activity = <Date 2021-05-19.18:28:35.119>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-05-19.18:13:27.800>
    closer = 'pablogsal'
    components = ['Parser']
    creation = <Date 2021-05-18.09:49:58.120>
    creator = 'Gerrit.Holl'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44168
    keywords = ['patch']
    message_count = 3.0
    messages = ['393865', '393962', '393963']
    nosy_count = 4.0
    nosy_names = ['Gerrit.Holl', 'lys.nikolaou', 'pablogsal', 'miss-islington']
    pr_nums = ['26210', '26247', '26250']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44168'
    versions = ['Python 3.9']

    @gerritholl
    Copy link
    Mannequin Author

    gerritholl mannequin commented May 18, 2021

    In Python 3.9.4, in a function call, when assigning a comprehension to a keyword argument, and the comprehension contains a spurious colon (if a list or set comprehension) or a missing value (when a dict comprehension), the syntax error message gives a hint that incorrectly suggests that the expression cannot contain an assignment:

    $ python
    Python 3.9.4 | packaged by conda-forge | (default, May 10 2021, 22:13:33)
    [GCC 9.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> f(a={x: for x in {}})
      File "<stdin>", line 1
        f(a={x: for x in {}})
          ^
    SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

    I certainly didn't mean "==" here. The syntax is correct if I either remove the :, or add a value after the :, such as:

    >> f(a={x:x for x in {}})
    >> f(a={x for x in {}})

    (correct syntax, succeeds if f is defined).

    The problem here has nothing to do with assignments being in the wrong place, so the message reported by cpython is incorrect.

    In Python 3.8.10 Python simply and correctly states that the syntax is incorrect:

    >>> f(a={x: for x in {}})
      File "<stdin>", line 1
        f(a={x: for x in {}})
                ^
    SyntaxError: invalid syntax

    I have not tried Python 3.10b1.

    @gerritholl gerritholl mannequin added 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels May 18, 2021
    @pablogsal
    Copy link
    Member

    New changeset d4a9264 by Pablo Galindo in branch '3.9':
    [3.9] bpo-44168: Fix error message in the parser for keyword arguments for invalid expressions (GH-26210) (GH-26250)
    d4a9264

    @pablogsal
    Copy link
    Member

    New changeset ec0699c by Miss Islington (bot) in branch '3.10':
    bpo-44168: Fix error message in the parser for keyword arguments for invalid expressions (GH-26210) (GH-26247)
    ec0699c

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant