Ignore unpacking in iteration-over-set (#5392)

Closes #5386.
This commit is contained in:
Charlie Marsh 2023-06-27 11:33:42 -04:00 committed by GitHub
parent 520f4f33c3
commit 502e15585d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View file

@ -36,3 +36,6 @@ for item in set(("apples", "lemons", "water")): # set constructor is fine
for number in {i for i in range(10)}: # set comprehensions are fine
print(number)
for item in {*numbers_set, 4, 5, 6}: # set unpacking is fine
print(f"I like {item}.")

View file

@ -1,4 +1,4 @@
use rustpython_parser::ast::{Expr, Ranged};
use rustpython_parser::ast::{self, Expr, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
@ -38,9 +38,15 @@ impl Violation for IterationOverSet {
/// PLC0208
pub(crate) fn iteration_over_set(checker: &mut Checker, expr: &Expr) {
if expr.is_set_expr() {
checker
.diagnostics
.push(Diagnostic::new(IterationOverSet, expr.range()));
let Expr::Set(ast::ExprSet { elts, .. }) = expr else {
return;
};
if elts.iter().any(Expr::is_starred_expr) {
return;
}
checker
.diagnostics
.push(Diagnostic::new(IterationOverSet, expr.range()));
}