Supported starred exceptions in length-one tuple detection (#7080)

This commit is contained in:
Charlie Marsh 2023-09-03 14:31:13 +01:00 committed by GitHub
parent b70dde4a77
commit b0d171ac19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 17 deletions

View file

@ -653,6 +653,17 @@ pub fn map_subscript(expr: &Expr) -> &Expr {
}
}
/// Given an [`Expr`] that can be starred, return the underlying starred expression.
pub fn map_starred(expr: &Expr) -> &Expr {
if let Expr::Starred(ast::ExprStarred { value, .. }) = expr {
// Ex) `*args`
value
} else {
// Ex) `args`
expr
}
}
/// Return `true` if the body uses `locals()`, `globals()`, `vars()`, `eval()`.
///
/// Accepts a closure that determines whether a given name (e.g., `"list"`) is a Python builtin.