mirror of https://github.com/astral-sh/ruff
avoid false positives when inheriting from functional `TypedDict`s
This commit is contained in:
parent
2949f76b47
commit
26c25bec82
|
|
@ -1100,6 +1100,20 @@ emp_invalid1 = Employee(department="HR")
|
||||||
emp_invalid2 = Employee(id=3)
|
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`
|
## Generic `TypedDict`
|
||||||
|
|
||||||
`TypedDict`s can also be generic.
|
`TypedDict`s can also be generic.
|
||||||
|
|
|
||||||
|
|
@ -169,11 +169,12 @@ impl<'db> ClassBase<'db> {
|
||||||
KnownInstanceType::SubscriptedProtocol(_) => Some(Self::Protocol),
|
KnownInstanceType::SubscriptedProtocol(_) => Some(Self::Protocol),
|
||||||
KnownInstanceType::TypeAliasType(_)
|
KnownInstanceType::TypeAliasType(_)
|
||||||
| KnownInstanceType::TypeVar(_)
|
| KnownInstanceType::TypeVar(_)
|
||||||
| KnownInstanceType::TypedDictType(_)
|
|
||||||
| KnownInstanceType::TypedDictSchema(_)
|
| KnownInstanceType::TypedDictSchema(_)
|
||||||
| KnownInstanceType::Deprecated(_)
|
| KnownInstanceType::Deprecated(_)
|
||||||
| KnownInstanceType::Field(_)
|
| KnownInstanceType::Field(_)
|
||||||
| KnownInstanceType::ConstraintSet(_) => None,
|
| KnownInstanceType::ConstraintSet(_) => None,
|
||||||
|
// TODO: Inherit the fields of synthesized `TypedDict`s.
|
||||||
|
KnownInstanceType::TypedDictType(_) => Some(Self::TypedDict),
|
||||||
},
|
},
|
||||||
|
|
||||||
Type::SpecialForm(special_form) => match special_form {
|
Type::SpecialForm(special_form) => match special_form {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue