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

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

Closed
gvanrossum opened this issue May 7, 2019 · 4 comments

Comments

@gvanrossum
Copy link
Member

gvanrossum commented May 7, 2019

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.

@msullivan
Copy link
Collaborator

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

@JelleZijlstra
Copy link
Member

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

@Bidek56
Copy link

Bidek56 commented Nov 21, 2019

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

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

No branches or pull requests

5 participants