mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-15 08:00:19 +00:00
Visit PEP 764 inline TypedDict
s' keys as non-type-expressions (#15073)
## Summary Resolves #10812. ## Test Plan `cargo nextest run` and `cargo insta test`.
This commit is contained in:
parent
8a98d88847
commit
d4ee6abf4a
6 changed files with 122 additions and 0 deletions
|
@ -126,6 +126,13 @@ pub fn is_pep_593_generic_type(qualified_name: &[&str]) -> bool {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn is_typed_dict(qualified_name: &[&str]) -> bool {
|
||||
matches!(
|
||||
qualified_name,
|
||||
["typing" | "typing_extensions", "TypedDict"]
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns `true` if a call path is `Literal`.
|
||||
pub fn is_standard_library_literal(qualified_name: &[&str]) -> bool {
|
||||
matches!(qualified_name, ["typing" | "typing_extensions", "Literal"])
|
||||
|
@ -216,6 +223,15 @@ pub fn is_pep_593_generic_member(member: &str) -> bool {
|
|||
matches!(member, "Annotated")
|
||||
}
|
||||
|
||||
/// Returns `true` if a name matches that of `TypedDict`.
|
||||
///
|
||||
/// See: <https://docs.python.org/3/library/typing.html>
|
||||
pub fn is_typed_dict_member(member: &str) -> bool {
|
||||
// Constructed by taking every pattern from `is_pep_593_generic`, removing all but
|
||||
// the last element in each pattern, and de-duplicating the values.
|
||||
matches!(member, "TypedDict")
|
||||
}
|
||||
|
||||
/// Returns `true` if a name matches that of the `Literal` generic.
|
||||
pub fn is_literal_member(member: &str) -> bool {
|
||||
matches!(member, "Literal")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue