Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
diceroll123 committed Nov 30, 2023
1 parent b4b47fb commit a6a286e
Showing 1 changed file with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ast::{Arguments, Stmt};
use ast::Stmt;
use ruff_python_ast::{self as ast, Expr, StmtFor};

use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
Expand Down Expand Up @@ -66,13 +66,15 @@ fn check_target_for_assignment(expr: &Expr, dict_name: &str, index_name: &str) -
// if we see the sequence subscript being modified, we'll stop emitting diagnostics
match expr {
Expr::Subscript(ast::ExprSubscript { value, slice, .. }) => {
if let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() {
if id == dict_name {
if let Expr::Name(ast::ExprName { id, .. }) = slice.as_ref() {
if id == index_name {
return true;
}
}
let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() else {
return false;
};
if id == dict_name {
let Expr::Name(ast::ExprName { id, .. }) = slice.as_ref() else {
return false;
};
if id == index_name {
return true;
}
}
false
Expand All @@ -93,13 +95,15 @@ impl<'a> Visitor<'_> for SubscriptVisitor<'a> {
range,
..
}) => {
if let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() {
if id == self.dict_name {
if let Expr::Name(ast::ExprName { id, .. }) = slice.as_ref() {
if id == self.index_name {
self.diagnostic_ranges.push(*range);
}
}
let Expr::Name(ast::ExprName { id, .. }) = value.as_ref() else {
return;
};
if id == self.dict_name {
let Expr::Name(ast::ExprName { id, .. }) = slice.as_ref() else {
return;
};
if id == self.index_name {
self.diagnostic_ranges.push(*range);
}
}
}
Expand Down Expand Up @@ -207,15 +211,11 @@ pub(crate) fn unnecessary_dict_index_lookup_comprehension(checker: &mut Checker,
}

fn dict_items(call_expr: &Expr, tuple_expr: &Expr) -> Option<(String, String, String)> {
let Expr::Call(ast::ExprCall {
func,
arguments: Arguments { args, .. },
..
}) = call_expr
else {
return None;
};
if !args.is_empty() {
let ast::ExprCall {
func, arguments, ..
} = call_expr.as_call_expr()?;

if !arguments.is_empty() {
return None;
}
let Expr::Attribute(ast::ExprAttribute { value, attr, .. }) = func.as_ref() else {
Expand Down

0 comments on commit a6a286e

Please sign in to comment.