diff --git a/crates/ty_python_semantic/resources/mdtest/typed_dict.md b/crates/ty_python_semantic/resources/mdtest/typed_dict.md index 085759654c..5cfcb3941a 100644 --- a/crates/ty_python_semantic/resources/mdtest/typed_dict.md +++ b/crates/ty_python_semantic/resources/mdtest/typed_dict.md @@ -1100,6 +1100,20 @@ emp_invalid1 = Employee(department="HR") emp_invalid2 = Employee(id=3) ``` +Fields from functional `TypedDict`s are not currently inherited: + +```py +from typing import TypedDict + +class X(TypedDict("Y", {"y": int})): + x: int + +x: X = {"x": 0} + +# error: [invalid-key] "Invalid key access on TypedDict `X`: Unknown key "y"" +x: X = {"y": 0, "x": 0} +``` + ## Generic `TypedDict` `TypedDict`s can also be generic. diff --git a/crates/ty_python_semantic/src/types/class_base.rs b/crates/ty_python_semantic/src/types/class_base.rs index 98dd5a501f..7418661c3c 100644 --- a/crates/ty_python_semantic/src/types/class_base.rs +++ b/crates/ty_python_semantic/src/types/class_base.rs @@ -169,11 +169,12 @@ impl<'db> ClassBase<'db> { KnownInstanceType::SubscriptedProtocol(_) => Some(Self::Protocol), KnownInstanceType::TypeAliasType(_) | KnownInstanceType::TypeVar(_) - | KnownInstanceType::TypedDictType(_) | KnownInstanceType::TypedDictSchema(_) | KnownInstanceType::Deprecated(_) | KnownInstanceType::Field(_) | KnownInstanceType::ConstraintSet(_) => None, + // TODO: Inherit the fields of synthesized `TypedDict`s. + KnownInstanceType::TypedDictType(_) => Some(Self::TypedDict), }, Type::SpecialForm(special_form) => match special_form {