Skip to content

Fix mutable default arguments and uninitialized EdaCommands.default_target - #542

Open
ThVerg wants to merge 1 commit into
olofk:mainfrom
ThVerg:fix/edacommands-robustness
Open

Fix mutable default arguments and uninitialized EdaCommands.default_target#542
ThVerg wants to merge 1 commit into
olofk:mainfrom
ThVerg:fix/edacommands-robustness

Conversation

@ThVerg

@ThVerg ThVerg commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Two related robustness fixes:

  • EdaCommands.default_target was never initialized in __init__, only created by set_default_target(). The guard in write() (if not self.default_target: raise RuntimeError(...)) therefore could never fire — a missing default target surfaced as an AttributeError instead of the intended "Missing default target" error. It is now initialized to None.
  • Mutable default arguments (order_only_deps=[], variables={}, args=[], fdto={}, env={}, …) are replaced with the conventional None pattern in EdaCommands.Command/add, legacy Edatool.configure/run/_run_tool/render_template, flow Node.__init__ and Edaflow._run_tool, and the tool-API render_template. Python evaluates these defaults once, so the same list/dict object is shared across every call that uses the default — Command.variables in particular was stored uncopied, so one caller mutating it would leak into unrelated commands.

No functional change for existing callers; full test suite passes (204 passed). Formatted with black 22.3.0.

EdaCommands.default_target only existed after set_default_target() was
called, so the missing-target check in write() raised AttributeError
instead of the intended RuntimeError. Initialize it to None.

Replace mutable default arguments (lists/dicts) with None throughout
EdaCommands, Edatool, Node and the flow/tool base classes. A shared
default dict like Command(variables={}) is aliased across all call
sites that rely on the default, so a mutation in one leaks into every
subsequent call.
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