Skip to content

Commit

Permalink
Tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 24, 2023
1 parent 92b80c9 commit 73172d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 4 additions & 6 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,9 @@ where
}
}
if self.settings.rules.enabled(Rule::SelfAssigningVariable) {
pylint::rules::self_assigning_variable(self, targets, value);
if let [target] = targets.as_slice() {
pylint::rules::self_assigning_variable(self, target, value);
}
}
if self.settings.rules.enabled(Rule::TypeParamNameMismatch) {
pylint::rules::type_param_name_mismatch(self, value, targets);
Expand Down Expand Up @@ -1649,11 +1651,7 @@ where
);
}
if self.enabled(Rule::SelfAssigningVariable) {
pylint::rules::self_assigning_variable(
self,
&[target.as_ref().clone()],
value,
);
pylint::rules::self_assigning_variable(self, target, value);
}
}
if self.enabled(Rule::UnintentionalTypeAnnotation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ impl Violation for SelfAssigningVariable {
}

/// PLW0127
pub(crate) fn self_assigning_variable(checker: &mut Checker, targets: &[Expr], value: &Expr) {
pub(crate) fn self_assigning_variable(checker: &mut Checker, target: &Expr, value: &Expr) {
// Assignments in class bodies are attributes (e.g., `x = x` assigns `x` to `self.x`, and thus
// is not a self-assignment).
if checker.semantic().scope().kind.is_class() {
return;
}

let [target] = targets else {
return;
};

fn inner(left: &Expr, right: &Expr, diagnostics: &mut Vec<Diagnostic>) {
match (left, right) {
(
Expand Down

0 comments on commit 73172d7

Please sign in to comment.