mirror of https://github.com/astral-sh/ruff
parent
520f4f33c3
commit
502e15585d
|
|
@ -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
|
for number in {i for i in range(10)}: # set comprehensions are fine
|
||||||
print(number)
|
print(number)
|
||||||
|
|
||||||
|
for item in {*numbers_set, 4, 5, 6}: # set unpacking is fine
|
||||||
|
print(f"I like {item}.")
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use rustpython_parser::ast::{Expr, Ranged};
|
use rustpython_parser::ast::{self, Expr, Ranged};
|
||||||
|
|
||||||
use ruff_diagnostics::{Diagnostic, Violation};
|
use ruff_diagnostics::{Diagnostic, Violation};
|
||||||
use ruff_macros::{derive_message_formats, violation};
|
use ruff_macros::{derive_message_formats, violation};
|
||||||
|
|
@ -38,9 +38,15 @@ impl Violation for IterationOverSet {
|
||||||
|
|
||||||
/// PLC0208
|
/// PLC0208
|
||||||
pub(crate) fn iteration_over_set(checker: &mut Checker, expr: &Expr) {
|
pub(crate) fn iteration_over_set(checker: &mut Checker, expr: &Expr) {
|
||||||
if expr.is_set_expr() {
|
let Expr::Set(ast::ExprSet { elts, .. }) = expr else {
|
||||||
checker
|
return;
|
||||||
.diagnostics
|
};
|
||||||
.push(Diagnostic::new(IterationOverSet, expr.range()));
|
|
||||||
|
if elts.iter().any(Expr::is_starred_expr) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checker
|
||||||
|
.diagnostics
|
||||||
|
.push(Diagnostic::new(IterationOverSet, expr.range()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue