Skip to content

N805 fix should be suppressed when another variable is using the recommended name #18459

@dscorbett

Description

@dscorbett

Summary

The fix for invalid-first-argument-name-for-method (N805) should be suppressed when the recommended parameter name is already taken by another variable used within that scope.

$ cat >n805.py <<'# EOF'
class C:
    def f(this):
        self = type(this).__name__
        print(self, this.__sizeof__())
C().f()
# EOF

$ python n805.py
C 16

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

$ cat n805.py
class C:
    def f(self):
        self = type(self).__name__
        print(self, self.__sizeof__())
C().f()

$ python n805.py
C 42

Version

ruff 0.11.12 (aee3af0 2025-05-29)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions