Skip to content

Implement assignment expressions (a.k.a. named expressions a.k.a. walrus operator) #6797

Closed

Description

@gvanrossum

Python 3.8 (currently in beta) supports a new expression operator, :=, dubbed the "walrus operator" (PEP 572). Mypy should support this. Parsing is not a problem -- when we use Python 3.8 to run mypy, we use the stdlib ast module which knows how to parse it. But mypy always treats this as a blocking error, saying "assignment expressions are not yet supported".

It would be nice if we supported this.

Activity

  1. msullivan commented on Jul 31, 2019

    @msullivan
    Collaborator

    There was somebody who expressed interest in implementing this but I'm not sure if anything came of it. Was it @JelleZijlstra?

  2. JelleZijlstra commented on Aug 1, 2019

    @JelleZijlstra
    Member

    #6899 came out of it :) It's still waiting for review

  3. Bidek56 commented on Nov 21, 2019

    @Bidek56

    PR #6899 was merged but I am not sure if work correctly.

    mypy with Python 3.8 with the example code:

    import re
    
    advertisement = '10% discount'
    discount = 0.0
    if (mo := re.search(r'(\d+)% discount', advertisement)):
        discount = float(mo.group(1)) / 100.0
    
    

    results in: error: Item "None" of "Optional[Match[str]]" has no attribute "group"
    Any ideas would be appreciated. Thanks

  4. JelleZijlstra commented on Nov 22, 2019

    @JelleZijlstra
    Member

    This is already covered in #7316. Closing this issue as there is general support for assignment expressions; I opened a series of more specific issues for smaller remaining problems.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions