Skip to content

fix: mutable default argument in _visit_with_path#8130

Open
stef41 wants to merge 1 commit intohuggingface:mainfrom
stef41:fix/mutable-default-visit-path
Open

fix: mutable default argument in _visit_with_path#8130
stef41 wants to merge 1 commit intohuggingface:mainfrom
stef41:fix/mutable-default-visit-path

Conversation

@stef41
Copy link
Copy Markdown

@stef41 stef41 commented Apr 11, 2026

Replace visit_path: _VisitPath = [] with Optional[_VisitPath] = None to avoid the mutable default argument anti-pattern (B006).

While the current callers always use visit_path + [k] (creating new lists), the shared default list is a latent bug that would surface if any future code path mutates visit_path in place (e.g. via .append()).

The fix initializes visit_path = [] inside the function body when None is passed.

Replace `visit_path: _VisitPath = []` with `Optional[_VisitPath] = None`
to avoid the mutable default argument anti-pattern (B006).

While the current callers always pass `visit_path + [k]` (creating new
lists), the shared default list is a latent bug that would surface if
any future code path uses `.append()` instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant