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

lambda expression no longer valid at comp_if in Python 3.9 #87921

Closed
gousaiyang mannequin opened this issue Apr 6, 2021 · 8 comments
Closed

lambda expression no longer valid at comp_if in Python 3.9 #87921

gousaiyang mannequin opened this issue Apr 6, 2021 · 8 comments
Labels
3.9 only security fixes 3.10 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@gousaiyang
Copy link
Mannequin

gousaiyang mannequin commented Apr 6, 2021

BPO 43755
Nosy @gvanrossum, @lysnikolaou, @pablogsal, @miss-islington, @tirkarthi, @gousaiyang
PRs
  • bpo-43755: Update docs to reflect that lambda is not allowed in comp_if since 3.9 #25231
  • [3.9] bpo-43755: Update docs to reflect that lambda is not allowed in comp_if since 3.9 (GH-25231) #25233
  • 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-04-06.22:17:20.933>
    created_at = <Date 2021-04-06.20:07:25.211>
    labels = ['type-bug', '3.9', '3.10']
    title = 'lambda expression no longer valid at comp_if in Python 3.9'
    updated_at = <Date 2021-04-07.18:18:03.202>
    user = 'https://github.com/gousaiyang'

    bugs.python.org fields:

    activity = <Date 2021-04-07.18:18:03.202>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-06.22:17:20.933>
    closer = 'pablogsal'
    components = []
    creation = <Date 2021-04-06.20:07:25.211>
    creator = 'gousaiyang'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43755
    keywords = ['patch']
    message_count = 8.0
    messages = ['390369', '390370', '390371', '390376', '390377', '390380', '390381', '390459']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'lys.nikolaou', 'pablogsal', 'miss-islington', 'xtreak', 'gousaiyang']
    pr_nums = ['25231', '25233']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43755'
    versions = ['Python 3.9', 'Python 3.10']

    @gousaiyang
    Copy link
    Mannequin Author

    gousaiyang mannequin commented Apr 6, 2021

    According to the documentation, a lambda expression at the comp_if position of a comprehension is allowed (can be parsed as lambda_expr_nocond). But this seems broken in Python 3.9 PEG parser. Example:

    user@host:/$ python3.8
    Python 3.8.9 (default, Apr  3 2021, 01:00:00)
    [GCC 7.5.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> [x for x in range(10) if lambda: 1]
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>>
    user@host:/$ python3.9
    Python 3.9.3 (default, Apr  3 2021, 00:51:37)
    [GCC 7.5.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> [x for x in range(10) if lambda: 1]
      File "<stdin>", line 1
        [x for x in range(10) if lambda: 1]
                                 ^
    SyntaxError: invalid syntax

    @gousaiyang gousaiyang mannequin added 3.9 only security fixes 3.10 only security fixes type-bug An unexpected behavior, bug, or error labels Apr 6, 2021
    @tirkarthi
    Copy link
    Member

    This looks like a duplicate of https://bugs.python.org/issue41848

    @gousaiyang
    Copy link
    Mannequin Author

    gousaiyang mannequin commented Apr 6, 2021

    OK I didn't find this duplicate issue. After reading that, I think we should update the documentation (https://docs.python.org/3/reference/expressions.html). comp_if ::= "if" expression_nocond [comp_iter] can become comp_if ::= "if" or_test [comp_iter], and all nocond stuffs can be removed.

    @gvanrossum
    Copy link
    Member

    Oh, nice improvement suggestion for the docs! Do you feel comfortable submitting a small PR for that?

    @gousaiyang
    Copy link
    Mannequin Author

    gousaiyang mannequin commented Apr 6, 2021

    I'll work on it soon.

    @pablogsal
    Copy link
    Member

    New changeset 0fdf11e by Saiyang Gou in branch 'master':
    bpo-43755: Update docs to reflect that lambda is not allowed in comp_if since 3.9 (GH-25231)
    0fdf11e

    @pablogsal
    Copy link
    Member

    Thanks for the quick fix, Saiyang Gou

    @pablogsal
    Copy link
    Member

    New changeset f91fc7a by Miss Islington (bot) in branch '3.9':
    bpo-43755: Update docs to reflect that lambda is not allowed in comp_if since 3.9 (GH-25231) (GH-25233)
    f91fc7a

    @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 3.10 only security fixes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants