mirror of https://github.com/astral-sh/ruff
Add support for TypedDict
This commit is contained in:
parent
d7f95ac6b6
commit
6a24351202
|
|
@ -58,3 +58,10 @@ y: int = 1
|
||||||
x: "Bar" = 1
|
x: "Bar" = 1
|
||||||
|
|
||||||
[first] = ["yup"]
|
[first] = ["yup"]
|
||||||
|
|
||||||
|
|
||||||
|
from typing import List, TypedDict
|
||||||
|
|
||||||
|
|
||||||
|
class Item(TypedDict):
|
||||||
|
nodes: List[TypedDict("Node", {"id": str})]
|
||||||
|
|
|
||||||
|
|
@ -559,6 +559,24 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if match_name_or_attr(func, "TypedDict") {
|
||||||
|
// TypedDict("a", {"a": int})
|
||||||
|
if args.len() > 1 {
|
||||||
|
if let ExprKind::Dict { keys, values } = &args[1].node {
|
||||||
|
for key in keys {
|
||||||
|
self.visit_expr(key);
|
||||||
|
}
|
||||||
|
for value in values {
|
||||||
|
self.visit_annotation(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypedDict("a", a=int)
|
||||||
|
for keyword in keywords {
|
||||||
|
let KeywordData { value, .. } = &keyword.node;
|
||||||
|
self.visit_annotation(value);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
visitor::walk_expr(self, expr);
|
visitor::walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue