avoid false positives when inheriting from functional `TypedDict`s

This commit is contained in:
Ibraheem Ahmed 2025-10-07 16:58:53 -04:00
parent 2949f76b47
commit 26c25bec82
2 changed files with 16 additions and 1 deletions

View File

@ -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.

View File

@ -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 {