Skip to content

chore(lint): enable ruff B006 (mutable data structures for argument defaults) - #4819

Open
chalfontchubby wants to merge 2 commits into
mainfrom
chore/ruff-b006
Open

chore(lint): enable ruff B006 (mutable data structures for argument defaults)#4819
chalfontchubby wants to merge 2 commits into
mainfrom
chore/ruff-b006

Conversation

@chalfontchubby

Copy link
Copy Markdown
Collaborator

Summary

Enables ruff's B006 - the classic Python trap where a {}/[] default argument is one object shared across every call that doesn't override it, so an in-place mutation in one call leaks into every other.

53 sites (26 production, 27 test). Every one was checked individually for an actual in-place mutation of the parameter (.append/.update/[key] =/etc, including through a local alias) before fixing - none found. Every site either only reads the default, or .copy()s/rebinds it before writing. So this closes a class of latent-but-currently-dormant bugs rather than fixing a live one; worth doing because a future edit that adds an in-place mutation to any of these would otherwise silently corrupt state across unrelated calls.

gecloud.py's async_get_smart_devices()/async_get_evc_devices() looked suspicious at first read (devices = previous, then devices.append(...)), but both rebind devices = [] before any append runs, so previous itself is never touched - included for completeness of the audit trail.

Standard fix throughout: param=None, then if param is None: param = {} (or []) as the first statement in the body, after any docstring.

Test plan

  • ruff check --select=F401,E713,F811,E722,F821,F841,B006 - clean
  • ./run_all --quick - passes
  • ./run_pre_commit - clean

🤖 Generated with Claude Code

chalfontchubby and others added 2 commits August 28, 2026 20:49
…efaults)

53 sites (26 production, 27 test) - the classic Python trap where a {}/[]
default is one object shared across every call that doesn't override it, so
an in-place mutation in one call leaks into every other. Every site checked
individually for an actual in-place mutation of the parameter before fixing
(.append/.update/[key]=/etc, including through a local alias) - none found;
all read the default or immediately .copy()/rebind before writing. So this
closes a class of latent-but-currently-dormant bugs rather than fixing a
live one.

gecloud.py's async_get_smart_devices()/async_get_evc_devices() looked
suspicious at first read (devices = previous, then devices.append(...)) but
both rebind devices = [] before any append, so previous itself is never
touched.

Standard fix throughout: param=None, then `if param is None: param = {}`
(or []) as the first statement in the body, after any docstring.
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.

2 participants