Fix mutable default arguments and uninitialized EdaCommands.default_target - #542
Open
ThVerg wants to merge 1 commit into
Open
Fix mutable default arguments and uninitialized EdaCommands.default_target#542ThVerg wants to merge 1 commit into
ThVerg wants to merge 1 commit into
Conversation
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.
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.
Two related robustness fixes:
EdaCommands.default_targetwas never initialized in__init__, only created byset_default_target(). The guard inwrite()(if not self.default_target: raise RuntimeError(...)) therefore could never fire — a missing default target surfaced as anAttributeErrorinstead of the intended "Missing default target" error. It is now initialized toNone.order_only_deps=[],variables={},args=[],fdto={},env={}, …) are replaced with the conventionalNonepattern inEdaCommands.Command/add, legacyEdatool.configure/run/_run_tool/render_template, flowNode.__init__andEdaflow._run_tool, and the tool-APIrender_template. Python evaluates these defaults once, so the same list/dict object is shared across every call that uses the default —Command.variablesin 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.