diff --git a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP008.py b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP008.py index d1a5ed5923d5de..59459132996a26 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP008.py +++ b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP008.py @@ -89,4 +89,19 @@ def foo(self): class B(A): def bar(self): - super(__class__, self).foo() \ No newline at end of file + super(__class__, self).foo() + + +# see: https://github.com/astral-sh/ruff/issues/18684 +class C: + def f(self): + super = print + super(C, self) + + +import builtins + + +class C: + def f(self): + builtins.super(C, self) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs index ba67756946f420..c98c917374d1be 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs @@ -66,7 +66,7 @@ impl AlwaysFixableViolation for SuperCallWithParameters { pub(crate) fn super_call_with_parameters(checker: &Checker, call: &ast::ExprCall) { // Only bother going through the super check at all if we're in a `super` call. // (We check this in `super_args` too, so this is just an optimization.) - if !is_super_call_with_arguments(call) { + if !is_super_call_with_arguments(call, checker) { return; } let scope = checker.semantic().current_scope(); @@ -167,10 +167,6 @@ pub(crate) fn super_call_with_parameters(checker: &Checker, call: &ast::ExprCall } /// Returns `true` if a call is an argumented `super` invocation. -fn is_super_call_with_arguments(call: &ast::ExprCall) -> bool { - if let Expr::Name(ast::ExprName { id, .. }) = call.func.as_ref() { - id == "super" && !call.arguments.is_empty() - } else { - false - } +fn is_super_call_with_arguments(call: &ast::ExprCall, checker: &Checker) -> bool { + checker.semantic().match_builtin_expr(&call.func, "super") && !call.arguments.is_empty() } diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP008.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP008.py.snap index 47a3305a796a9d..8a25f8e14bf7d3 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP008.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP008.py.snap @@ -142,3 +142,22 @@ UP008.py:92:14: UP008 [*] Use `super()` instead of `super(__class__, self)` 91 91 | def bar(self): 92 |- super(__class__, self).foo() 92 |+ super().foo() +93 93 | +94 94 | +95 95 | # see: https://github.com/astral-sh/ruff/issues/18684 + +UP008.py:107:23: UP008 [*] Use `super()` instead of `super(__class__, self)` + | +105 | class C: +106 | def f(self): +107 | builtins.super(C, self) + | ^^^^^^^^^ UP008 + | + = help: Remove `__super__` parameters + +ℹ Unsafe fix +104 104 | +105 105 | class C: +106 106 | def f(self): +107 |- builtins.super(C, self) + 107 |+ builtins.super()