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.
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:
In most cases, I wouldn't want the caller to have to seed the
_seenparam or even know that it exists, as imo, that's just an implementation detail.