-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Store the type for assignment expr targets #9479
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
Conversation
cc @gvanrossum since you brought this ticket to my attention. Someone should review to see if this is the right solution. At the very least it seems to fix the example presented by the OP. |
This is a good start! From the CI failure we learn that there's exactly one test that fails: |
Okay, this is green now for both the |
Thank you so much! I'm swamped but will review over the weekend (unless @hauntsaninja beats me to it :-). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! You should be proud of yourself. Do you want me to pick another issue for you to try?
Thanks for fixing this! I was a little bit curious about the If you're willing to accept a small suggestion, I think it might be nice to fix by moving Line 2817 in 0b4a2c9
(visit_assignment_expr gets called by the typ = node.accept(self) on line 3782)
It looks like |
Sorry I didn't wait for you @hauntsaninja. |
Not at all, thank you for being proactive! |
Description
Assignment (walrus) expressions don't currently store their target types into the checker's type map, leading to an internal error when mypy goes to infer the type of that name downstream. This PR stores the assignment target's type explicitly. If this is not the right approach, feel free to comment/close this. I just wanted to push this up so there's a demo of a potential fix.
Fixes #9054
Test Plan
Still a work in progress, need to add tests.A test has been added that reproduces the OP's report, and this PR fixes it.