Skip to content

Commit

Permalink
Avoid raising SIM911 for attribute calls
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Apr 24, 2024
1 parent 7c8c1c7 commit 3e97d77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ def foo(d: dict[str, str]) -> None:
...

items = zip(x.keys(), x.values()) # OK

items.bar = zip(x.keys(), x.values()) # OK
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ast::{ExprAttribute, ExprName, Identifier};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::{self as ast, Arguments, Expr, ExprCall};
use ruff_python_ast::{self as ast, Arguments, Expr};
use ruff_text_size::Ranged;

use crate::{checkers::ast::Checker, fix::snippet::SourceCodeSnippet};
Expand Down Expand Up @@ -59,8 +59,8 @@ impl AlwaysFixableViolation for ZipDictKeysAndValues {
}

/// SIM911
pub(crate) fn zip_dict_keys_and_values(checker: &mut Checker, expr: &ExprCall) {
let ExprCall {
pub(crate) fn zip_dict_keys_and_values(checker: &mut Checker, expr: &ast::ExprCall) {
let ast::ExprCall {
func,
arguments: Arguments { args, keywords, .. },
..
Expand All @@ -72,9 +72,6 @@ pub(crate) fn zip_dict_keys_and_values(checker: &mut Checker, expr: &ExprCall) {
}] if name.as_str() == "strict" => {}
_ => return,
};
if matches!(func.as_ref(), Expr::Name(ExprName { id, .. }) if id != "zip") {
return;
}
let [arg1, arg2] = &args[..] else {
return;
};
Expand All @@ -87,6 +84,9 @@ pub(crate) fn zip_dict_keys_and_values(checker: &mut Checker, expr: &ExprCall) {
if var1.id != var2.id || attr1 != "keys" || attr2 != "values" {
return;
}
if !checker.semantic().match_builtin_expr(func, "zip") {
return;
}

let Some(binding) = checker
.semantic()
Expand Down

0 comments on commit 3e97d77

Please sign in to comment.