chore(lint): enable ruff B006 (mutable data structures for argument defaults) - #4819
Open
chalfontchubby wants to merge 2 commits into
Open
chore(lint): enable ruff B006 (mutable data structures for argument defaults)#4819chalfontchubby wants to merge 2 commits into
chalfontchubby wants to merge 2 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'sasync_get_smart_devices()/async_get_evc_devices()looked suspicious at first read (devices = previous, thendevices.append(...)), but both rebinddevices = []before any append runs, sopreviousitself is never touched - included for completeness of the audit trail.Standard fix throughout:
param=None, thenif 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