Skip to content

RUF052: Don't flag assignments to private function arguments #14968

@aiudirog

Description

@aiudirog

This is a follow up to #14796: attempting to assign a private function parameter still gets flagged in Ruff v0.8.3 (playground)

My primary use case for private parameters is when I need to track what I've seen when recursing through a potentially circular graph:

class Node:

    connected: list[Node]

    def recurse(self, *, _seen: set[Node] | None = None):
        if _seen is None:
            _seen = set()  # Local dummy variable `_seen` is accessed (RUF052)
        elif self in _seen:
            return
        _seen.add(self)
        for other in self.connected:
            other.recurse(_seen=_seen)

In most cases, I wouldn't want the caller to have to seed the _seen param or even know that it exists, as imo, that's just an implementation detail.

Metadata

Metadata

Assignees

Labels

acceptedReady for implementationhelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions