Skip to content

UP008 should not apply when __class__ is a local variable #20491

@dscorbett

Description

@dscorbett

Summary

When the first argument to super in a method is a local variable named __class__, super-call-with-parameters (UP008) should not apply. Example:

$ cat >up008.py <<'# EOF'
class A:
    def f(self):
        return 1
class B(A):
    def f(self):
        return 2
class C(B):
    def f(self):
        __class__ = B
        return super(__class__, self).f()
print(C().f())
# EOF

$ python up008.py
1

$ ruff --isolated check up008.py --select UP008 --unsafe-fixes --fix
Found 1 error (1 fixed, 0 remaining).

$ python up008.py 2>&1 | tail -n 1
RuntimeError: super(): __class__ cell not found

This isn’t a problem in the usual case where __class__ is nonlocal, whether explicitly via nonlocal __class__ or implicitly by not being assigned to.

Version

ruff 0.13.1 (706be0a 2025-09-18)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions