Add PYI034 for flake8-pyi plugin (#4764)

This commit is contained in:
qdegraaf 2023-06-02 04:15:57 +02:00 committed by GitHub
parent c68686b1de
commit fcbf5c3fae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 918 additions and 2 deletions

View file

@ -684,12 +684,27 @@ pub fn collect_arg_names<'a>(arguments: &'a Arguments) -> FxHashSet<&'a str> {
/// callable.
pub fn map_callable(decorator: &Expr) -> &Expr {
if let Expr::Call(ast::ExprCall { func, .. }) = decorator {
// Ex) `@decorator()`
func
} else {
// Ex) `@decorator`
decorator
}
}
/// 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.
pub fn map_subscript(expr: &Expr) -> &Expr {
if let Expr::Subscript(ast::ExprSubscript { value, .. }) = expr {
// Ex) `Iterable[T]`
value
} else {
// Ex) `Iterable`
expr
}
}
/// Returns `true` if a statement or expression includes at least one comment.
pub fn has_comments<T>(located: &T, locator: &Locator) -> bool
where