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

Unpacking without parentheses is allowed since 3.9 #90881

Closed
pablogsal opened this issue Feb 11, 2022 · 11 comments
Closed

Unpacking without parentheses is allowed since 3.9 #90881

pablogsal opened this issue Feb 11, 2022 · 11 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@pablogsal
Copy link
Member

BPO 46725
Nosy @gvanrossum, @terryjreedy, @jwilk, @serhiy-storchaka, @JelleZijlstra, @lysnikolaou, @pablogsal, @miss-islington, @isidentical, @erlend-aasland
PRs
  • bpo-46725: Document starred expressions in for statements #31481
  • 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 2022-02-22.18:31:20.414>
    created_at = <Date 2022-02-11.18:10:30.648>
    labels = ['interpreter-core', '3.9', '3.10', '3.11']
    title = 'Unpacking without parentheses is allowed since 3.9'
    updated_at = <Date 2022-02-22.18:31:20.413>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2022-02-22.18:31:20.413>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-22.18:31:20.414>
    closer = 'pablogsal'
    components = ['Parser']
    creation = <Date 2022-02-11.18:10:30.648>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46725
    keywords = ['patch']
    message_count = 11.0
    messages = ['413089', '413090', '413091', '413092', '413098', '413101', '413501', '413507', '413698', '413703', '413718']
    nosy_count = 10.0
    nosy_names = ['gvanrossum', 'terry.reedy', 'jwilk', 'serhiy.storchaka', 'JelleZijlstra', 'lys.nikolaou', 'pablogsal', 'miss-islington', 'BTaskaya', 'erlendaasland']
    pr_nums = ['31481']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46725'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @pablogsal
    Copy link
    Member Author

    Seems that this is allowed since the PEG parser rewrite:

    for x in *a, *b:
        print(x)

    but I cannot find anywhere were we discussed this. I am not sure if we should keep it or treat it as a bug and fix it.

    @pablogsal pablogsal added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Feb 11, 2022
    @isidentical
    Copy link
    Member

    Since this was already allowed in 3.9 and 3.10 stable relases, and since it is consistent with the RHS of an assignment (something = *a, *b); I'd lean towards keeping it (and maybe fixing the old parser's grammar to reflect that) and documenting this.

    @JelleZijlstra
    Copy link
    Member

    I'd lean towards keeping this syntax:

    • It's already been out for two releases, so there's user code out there relying on it. (In fact we found out about this because somebody complained that Black's parser couldn't handle this code.)
    • The syntax isn't obviously confusing and the meaning is clear.
    • It's not hard to parse; it was easy to adjust Black's parser to allow it.

    @erlend-aasland
    Copy link
    Contributor

    +1 (what Jelle said)

    @gvanrossum
    Copy link
    Member

    Let's just document it for 3.11.

    @pablogsal
    Copy link
    Member Author

    Will prepare a PR

    @terryjreedy
    Copy link
    Member

    Allowing no parentheses is also consistent with the following:
    for x in 1,2,3: print(x)

    @gvanrossum
    Copy link
    Member

    Adding jwilk back (a bpo interaction with browser form caching makes this happen frequently).

    @serhiy-storchaka
    Copy link
    Member

    What exactly was happened? What rule was changed? Can it cause other changes which allow ambiguous code or change semantic?

    @pablogsal
    Copy link
    Member Author

    What happened is that the new grammar using the PEG parser used the equivalent of starred_testlist instead of testlist for the iterable list of for statements.

    The only extra thing allowed is starred elements, that are interpreted as if you are building a tuple without parentheses.

    @miss-islington
    Copy link
    Contributor

    New changeset 7fb94fd by Pablo Galindo Salgado in branch 'main':
    bpo-46725: Document starred expressions in for statements (GH-31481)
    7fb94fd

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    8 participants