-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Base {} Dict Should Infer from Function Return Type #18700
Comments
Hey, is it OK if I contribute to solving this one? Never contributed to open-source before, but I like mypy and would like to try. |
Sure but I suspect an issue labelled good first issue would be better. Edit: oops, they're all taken. Looking through recent issues, I would suspect #18692 is an easier fix than this (though I'm not familiar enough with mypy to know for sure without... doing it myself). |
Thank you, I will try to fix this one then. I will find something easier if I make no progress in a couple of weeks.
Yeah, since all “good first issue”s are taken I decided to try this one. And I like the issue because I experienced it myself. |
I think I can take this one up this weekend. Happy to pair with @Bellkross |
Would be happy to pair up @dibrinsofor |
@dibrinsofor , I will not be working on this issue, feel free to do it without me, fyi. Something came up and my plans for nearest several weeks have changed |
@dibrinsofor hey, I am back and can work on the issue now. We can get in contact this weekend if you want to. |
@Bellkross sounds good. I can shoot you an email and we can arrange on a time. |
I just realized that I would rather work on an issue alone, so will let @dibrinsofor solve this one since they are the author. Apologies for confusion. Will be looking for something else. |
I was thinking about this today, and I'm not sure we should modify how propagation (or elaboration?) works here, maybe just introduce a special case to avoid raising errors in situations like this, but even then, it does not seem very beneficial. For one, there's no control flow to trigger narrowing, and even if there were, I don’t see how propagating the refined type back to the initial definition would be beneficial. But i did notice some nits while probing this.
This raises this error without a hint, I just need some go ahead, and I will pivot to addressing the nits instead. |
An empty tuple can be annotated as having no contents so it doesn't need an annotation. (I'm surprised calling I would recommend looking at how currently mypy handles inferring types given: x = []
x.append(5) and extend that to a |
Bug Report
I think this may be a possible refinement bug. Mypy flags an error on the assignment line, and not the return statement. So it is clear Mypy flags
{}
as a subtype of{str, str}
, but I think this should be one of those cases where having refinements should reduce the annotation burden on developers. Unless we want to throw an error because of imprecision.To Reproduce
reproducible link: Gist Playground
Expected Behavior
I would expect Mypy to notice the reveal_type(x) as dict[str, str] based off the functions return type and not raise an error.
Actual Behavior
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: