[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
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

Narrow types for walrus assignment in if statements #8258

Merged
merged 3 commits into from Jan 8, 2020
+21 −9

Conversation

Copy link
Contributor

hauntsaninja commented Jan 8, 2020

Fixes #7313
Fixes #7316

This comment has been minimized.

Copy link
Contributor Author

hauntsaninja commented Jan 8, 2020

Let me know if there's a better way to handle the partial types that can result! Or if there are more tests I should be adding. There's a lot that I don't know :-)

I guess one thing I was wondering if there's a way to improve the hint resulting from the partial type (see line 296 on test-data/unit/check-python38.test). Worried that it might be hard for users to realise that you would have to put the annotation on another line.

This comment has been minimized.

Copy link
Collaborator

JelleZijlstra commented Jan 8, 2020

I doubt that a lot of users are going to write if (x := []): (why would you do that except to confuse a typechecker?), so I don't think it's worth it to invest too much in improving the error message. We can revisit that if we get user complaints.

This comment has been minimized.

Copy link
Contributor

TH3CHARLie commented Jan 8, 2020

Will you have an interest in testing against #7313 to see if the PR also happens to fix that issue? (Although I am not sure at all whether these issues come from the same source)

This comment has been minimized.

Copy link
Contributor Author

hauntsaninja commented Jan 8, 2020

Yes, it fixes #7313 too (updated the PR to mention that). A test exists for that issue on line 269 of test-data/unit/check-python38.test.

Looking through other issues, it does not fix #8236, but I can maybe work on that (in a separate PR).

Copy link
Collaborator

msullivan left a comment

This seems good to me and is really important since this sort of thing is the killer feature of assignment expressions.

msullivan merged commit 33fc8a3 into python:master Jan 8, 2020
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
hauntsaninja deleted the hauntsaninja:narrow_walrus branch Jan 8, 2020
hauntsaninja added a commit to hauntsaninja/mypy that referenced this pull request Jan 9, 2020
jhackshaw-dds mentioned this pull request Feb 14, 2020
3 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants