Skip to content

Ignore partial type in base when inferring/checking #13538

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 2 commits into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2709,8 +2709,10 @@ def get_variable_type_context(self, inferred: Var) -> Type | None:
if inferred.info:
for base in inferred.info.mro[1:]:
base_type, base_node = self.lvalue_type_from_base(inferred, base)
if base_type and not (
isinstance(base_node, Var) and base_node.invalid_partial_type
if (
base_type
and not (isinstance(base_node, Var) and base_node.invalid_partial_type)
and not isinstance(base_type, PartialType)
):
type_contexts.append(base_type)
# Use most derived supertype as type context if available.
Expand Down Expand Up @@ -2813,6 +2815,8 @@ def check_compatibility_all_supers(
continue

base_type, base_node = self.lvalue_type_from_base(lvalue_node, base)
if isinstance(base_type, PartialType):
base_type = None

if base_type:
assert base_node is not None
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -3328,3 +3328,12 @@ class C(P, M):
x = [] # E: Need type annotation for "x" (hint: "x: List[<type>] = ...")
reveal_type(C.x) # N: Revealed type is "builtins.list[Any]"
[builtins fixtures/list.pyi]

[case testNoPartialInSupertypeAsContext]
class A:
args = {} # E: Need type annotation for "args" (hint: "args: Dict[<type>, <type>] = ...")
def f(self) -> None:
value = {1: "Hello"}
class B(A):
args = value
[builtins fixtures/dict.pyi]