-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix type inference regression with partial types #8091
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
Not ready to merge -- there seems to a problem with this PR. |
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.
This fix looks better, I have couple optional suggestions.
mypy/checker.py
Outdated
if is_valid_inferred_type(rvalue_type): | ||
var.type = rvalue_type | ||
else: | ||
var.type = self.inference_error_fallback_type(rvalue_type) |
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.
What if one just assigns the variable twice (without reading it), would it silence the error on first assignment? Not that it is too bad, but still may be surprising.
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.
Yeah, a good catch! This behavior is inconsistent. I'll try to fix it.
mypy/checker.py
Outdated
@@ -2785,6 +2788,7 @@ def infer_variable_type(self, name: Var, lvalue: Lvalue, | |||
init_type = get_proper_type(init_type) | |||
if isinstance(init_type, DeletedType): | |||
self.msg.deleted_as_rvalue(init_type, context) | |||
name.type = AnyType(TypeOfAny.from_error) |
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.
Is there a test for this?
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.
No, and this is kind of an unrelated thing that I encountered when trying a different fix. I might take this out of this PR.
Don't infer types such as
List[<nothing>]
; inferList[Any]
instead.Fixes #8090.