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

Improve error message in the parser when using un-parenthesised tuples in comprehensions #87183

Closed
pablogsal opened this issue Jan 24, 2021 · 3 comments

Comments

@pablogsal
Copy link
Member

BPO 43017
Nosy @aroberge, @lysnikolaou, @pablogsal
PRs
  • bpo-43017: Improve error message for unparenthesised tuples in comprehensions #24314
  • 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-01-31.22:53:06.078>
    created_at = <Date 2021-01-24.18:00:46.555>
    labels = []
    title = 'Improve error message in the parser when using un-parenthesised tuples in comprehensions'
    updated_at = <Date 2021-01-31.22:53:06.078>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2021-01-31.22:53:06.078>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-01-31.22:53:06.078>
    closer = 'pablogsal'
    components = []
    creation = <Date 2021-01-24.18:00:46.555>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43017
    keywords = ['patch']
    message_count = 3.0
    messages = ['385586', '385655', '386045']
    nosy_count = 3.0
    nosy_names = ['aroberge', 'lys.nikolaou', 'pablogsal']
    pr_nums = ['24314']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue43017'
    versions = []

    @pablogsal
    Copy link
    Member Author

    I have seen this confusion many users over the years. Instead of showing:

    ❯ python -c '[x,z for x,y in something]'
    File "<string>", line 1
    [x,z for x,y in something]
    ^
    SyntaxError: invalid syntax

    We can show:

    ❯ ./python -c '[x,z for x,y in something]'
    File "<string>", line 1
    [x,z for x,y in something]
    ^
    SyntaxError: did you forgot parentheses around the comprehension target?

    @aroberge
    Copy link
    Mannequin

    aroberge mannequin commented Jan 25, 2021

    Such a change would be very useful and appreciated by other users as reported on aroberge/friendly#167 and asked about on StackOverflow
    https://stackoverflow.com/questions/60986850/why-does-creating-a-list-of-tuples-using-list-comprehension-requires-parentheses

    @pablogsal
    Copy link
    Member Author

    New changeset 835f14f by Pablo Galindo in branch 'master':
    bpo-43017: Improve error message for unparenthesised tuples in comprehensions (GH24314)
    835f14f

    @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
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant