mirror of https://github.com/astral-sh/ruff
Avoid false-positive in chained type calls (#2663)
This commit is contained in:
parent
9f9f25ff7c
commit
7482a4a5b8
|
|
@ -10,3 +10,4 @@ y = x.dtype.type(0.0)
|
||||||
# OK
|
# OK
|
||||||
type = lambda *args, **kwargs: None
|
type = lambda *args, **kwargs: None
|
||||||
type("")
|
type("")
|
||||||
|
type(arg)(" ")
|
||||||
|
|
|
||||||
|
|
@ -2280,7 +2280,7 @@ where
|
||||||
|
|
||||||
// pyupgrade
|
// pyupgrade
|
||||||
if self.settings.rules.enabled(&Rule::TypeOfPrimitive) {
|
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) {
|
if self.settings.rules.enabled(&Rule::DeprecatedUnittestAlias) {
|
||||||
pyupgrade::rules::deprecated_unittest_alias(self, func);
|
pyupgrade::rules::deprecated_unittest_alias(self, func);
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,12 @@ impl AlwaysAutofixableViolation for TypeOfPrimitive {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// UP003
|
/// 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 {
|
if args.len() != 1 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if !checker
|
if !checker
|
||||||
.resolve_call_path(func)
|
.resolve_call_path(expr)
|
||||||
.map_or(false, |call_path| call_path.as_slice() == ["", "type"])
|
.map_or(false, |call_path| call_path.as_slice() == ["", "type"])
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue