mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
parent
520f4f33c3
commit
502e15585d
2 changed files with 14 additions and 5 deletions
|
@ -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}.")
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue