Skip to content

Commit 4cfacc6

Browse files
authored
Ignore partial type in base when inferring/checking (#13538)
Fixes #13536
1 parent 09b8b55 commit 4cfacc6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

mypy/checker.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2709,8 +2709,10 @@ def get_variable_type_context(self, inferred: Var) -> Type | None:
27092709
if inferred.info:
27102710
for base in inferred.info.mro[1:]:
27112711
base_type, base_node = self.lvalue_type_from_base(inferred, base)
2712-
if base_type and not (
2713-
isinstance(base_node, Var) and base_node.invalid_partial_type
2712+
if (
2713+
base_type
2714+
and not (isinstance(base_node, Var) and base_node.invalid_partial_type)
2715+
and not isinstance(base_type, PartialType)
27142716
):
27152717
type_contexts.append(base_type)
27162718
# Use most derived supertype as type context if available.
@@ -2813,6 +2815,8 @@ def check_compatibility_all_supers(
28132815
continue
28142816

28152817
base_type, base_node = self.lvalue_type_from_base(lvalue_node, base)
2818+
if isinstance(base_type, PartialType):
2819+
base_type = None
28162820

28172821
if base_type:
28182822
assert base_node is not None

test-data/unit/check-inference.test

+9
Original file line numberDiff line numberDiff line change
@@ -3328,3 +3328,12 @@ class C(P, M):
33283328
x = [] # E: Need type annotation for "x" (hint: "x: List[<type>] = ...")
33293329
reveal_type(C.x) # N: Revealed type is "builtins.list[Any]"
33303330
[builtins fixtures/list.pyi]
3331+
3332+
[case testNoPartialInSupertypeAsContext]
3333+
class A:
3334+
args = {} # E: Need type annotation for "args" (hint: "args: Dict[<type>, <type>] = ...")
3335+
def f(self) -> None:
3336+
value = {1: "Hello"}
3337+
class B(A):
3338+
args = value
3339+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)