Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion crates/ruff_linter/resources/test/fixtures/pyupgrade/UP008.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,19 @@ def foo(self):

class B(A):
def bar(self):
super(__class__, self).foo()
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)
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading