Skip to content

Commit

Permalink
Avoid false-positive in chained type calls (#2663)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 8, 2023
1 parent 9f9f25f commit 7482a4a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/ruff/resources/test/fixtures/pyupgrade/UP003.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
# OK
type = lambda *args, **kwargs: None
type("")
type(arg)(" ")
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,7 @@ where

// pyupgrade
if self.settings.rules.enabled(&Rule::TypeOfPrimitive) {
pyupgrade::rules::type_of_primitive(self, expr, func, args);
pyupgrade::rules::type_of_primitive(self, expr, args);
}
if self.settings.rules.enabled(&Rule::DeprecatedUnittestAlias) {
pyupgrade::rules::deprecated_unittest_alias(self, func);
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/pyupgrade/rules/type_of_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ impl AlwaysAutofixableViolation for TypeOfPrimitive {
}

/// UP003
pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, args: &[Expr]) {
if args.len() != 1 {
return;
}
if !checker
.resolve_call_path(func)
.resolve_call_path(expr)
.map_or(false, |call_path| call_path.as_slice() == ["", "type"])
{
return;
Expand Down

0 comments on commit 7482a4a

Please sign in to comment.