mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-30 15:17:40 +00:00
Allow named expressions in __all__
assignments (#7673)
## Summary This PR adds support for named expressions when analyzing `__all__` assignments, as per https://github.com/astral-sh/ruff/issues/7672. It also loosens the enforcement around assignments like: `__all__ = list(some_other_expression)`. We shouldn't flag these as invalid, even though we can't analyze the members, since we _know_ they evaluate to a `list`. Closes https://github.com/astral-sh/ruff/issues/7672. ## Test Plan `cargo test`
This commit is contained in:
parent
fbbc982c29
commit
0a8cad2550
3 changed files with 35 additions and 5 deletions
|
@ -81,17 +81,21 @@ where
|
|||
| Expr::Tuple(ast::ExprTuple { elts, .. }) => {
|
||||
return (Some(elts), DunderAllFlags::empty());
|
||||
}
|
||||
Expr::ListComp(_) | Expr::SetComp(_) | Expr::GeneratorExp(_) => {
|
||||
// Allow comprehensions, even though we can't statically analyze
|
||||
// them.
|
||||
_ => {
|
||||
// We can't analyze other expressions, but they must be
|
||||
// valid, since the `list` or `tuple` call will ultimately
|
||||
// evaluate to a list or tuple.
|
||||
return (None, DunderAllFlags::empty());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Expr::NamedExpr(ast::ExprNamedExpr { value, .. }) => {
|
||||
// Allow, e.g., `__all__ += (value := ["A", "B"])`.
|
||||
return extract_elts(value, is_builtin);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
(None, DunderAllFlags::INVALID_FORMAT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue