Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pyupgrade/UP008.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,19 @@ class C(B):
def f(self):
C = B # Local variable C shadows the class name
return super(C, self).f() # Should NOT trigger UP008


# See: https://github.com/astral-sh/ruff/issues/20491
# UP008 should not apply when __class__ is a local variable
class A:
def f(self):
return 1

class B(A):
def f(self):
return 2

class C(B):
def f(self):
__class__ = B # Local variable __class__ shadows the implicit __class__
return super(__class__, self).f() # Should NOT trigger UP008
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ pub(crate) fn super_call_with_parameters(checker: &Checker, call: &ast::ExprCall
};

if !((first_arg_id == "__class__"
// If the first argument is __class__, check if it's a local variable.
// If so, don't apply UP008.
&& !checker.semantic().current_scope().has("__class__")
|| (first_arg_id == parent_name.as_str()
// If the first argument matches the class name, check if it's a local variable
// that shadows the class name. If so, don't apply UP008.
Expand Down
Loading