Visit PEP 764 inline TypedDicts' keys as non-type-expressions (#15073)

## Summary

Resolves #10812.

## Test Plan

`cargo nextest run` and `cargo insta test`.
This commit is contained in:
InSync 2024-12-30 16:34:55 +07:00 committed by GitHub
parent 8a98d88847
commit d4ee6abf4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 122 additions and 0 deletions

View file

@ -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")