Skip to content

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

Merged
merged 4 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix type inference regression
  • Loading branch information
JukkaL committed Dec 5, 2019
commit 268092fa4b6c2a110b968277ce66e9003709b1a8
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ def try_infer_partial_generic_type_from_assignment(self,
rvalue_type = get_proper_type(rvalue_type)
if isinstance(rvalue_type, Instance):
if rvalue_type.type == typ.type:
var.type = rvalue_type
self.infer_variable_type(var, lvalue, rvalue_type, rvalue)
del partial_types[var]
elif isinstance(rvalue_type, AnyType):
var.type = fill_typevars_with_any(typ.type)
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,17 @@ oo.update(d)
reveal_type(oo) # N: Revealed type is 'collections.OrderedDict[builtins.int*, builtins.str*]'
[builtins fixtures/dict.pyi]

[case testEmptyCollectionAssignedToVariableTwice]
x = [] # E: Need type annotation for 'x' (hint: "x: List[<type>] = ...")
y = x
x = []
reveal_type(x) # N: Revealed type is 'builtins.list[Any]'
d = {} # E: Need type annotation for 'd' (hint: "d: Dict[<type>, <type>] = ...")
z = d
d = {}
reveal_type(d) # N: Revealed type is 'builtins.dict[Any, Any]'
[builtins fixtures/dict.pyi]

[case testInferAttributeInitializedToEmptyAndAssigned]
class C:
def __init__(self) -> None:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy