diff --git a/mypy/checker.py b/mypy/checker.py index 415cb0d5cab4..106c8e9a0351 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -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. @@ -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 diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index ffcd6d8d94dd..26b468342beb 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -3328,3 +3328,12 @@ class C(P, M): x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") 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[, ] = ...") + def f(self) -> None: + value = {1: "Hello"} + class B(A): + args = value +[builtins fixtures/dict.pyi]