Avoid false-positive in chained type calls (#2663)

This commit is contained in:
Charlie Marsh 2023-02-08 12:18:36 -05:00 committed by GitHub
parent 9f9f25ff7c
commit 7482a4a5b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View File

@ -10,3 +10,4 @@ y = x.dtype.type(0.0)
# OK
type = lambda *args, **kwargs: None
type("")
type(arg)(" ")

View File

@ -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);

View File

@ -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;