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

Narrow types for walrus assignment in if statements #8258

Merged
merged 3 commits into from
Jan 8, 2020

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Jan 8, 2020

Fixes #7313
Fixes #7316

@hauntsaninja
Copy link
Collaborator Author

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.

@JelleZijlstra
Copy link
Member

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.

@TH3CHARLie
Copy link
Collaborator

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)

@hauntsaninja
Copy link
Collaborator Author

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 msullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants