[flake8-pyi] Implement PYI064 (#11325)

## Summary

Implements `Y064` from `flake8-pyi` and its autofix.

## Test Plan

`cargo test` / `cargo insta review`
This commit is contained in:
Tushar Sadhwani 2024-05-29 05:27:13 +05:30 committed by GitHub
parent 9a3b9f9fb5
commit e0169d8dea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 389 additions and 5 deletions

View file

@ -657,15 +657,14 @@ pub fn map_callable(decorator: &Expr) -> &Expr {
}
}
/// Given an [`Expr`] that can be callable or not (like a decorator, which could
/// be used with or without explicit call syntax), return the underlying
/// callable.
/// Given an [`Expr`] that can be a [`ExprSubscript`][ast::ExprSubscript] or not
/// (like an annotation that may be generic or not), return the underlying expr.
pub fn map_subscript(expr: &Expr) -> &Expr {
if let Expr::Subscript(ast::ExprSubscript { value, .. }) = expr {
// Ex) `Iterable[T]`
// Ex) `Iterable[T]` => return `Iterable`
value
} else {
// Ex) `Iterable`
// Ex) `Iterable` => return `Iterable`
expr
}
}