Description
Currently HConfigChild.text is mutable (modified during negate()), and comments/tags are mutable sets. This means remediation can mutate the source tree, requiring deep_copy() to avoid side effects.
Proposed Change
Make tree nodes immutable after construction:
negate() returns a new node rather than mutating self.text
comments and tags become frozenset (or copy-on-write)
- Tree modifications create new branches rather than mutating in place
Benefits
- Eliminates mutation bugs (remediation can't corrupt the source config)
deep_copy() becomes unnecessary in most cases
- Thread-safe by default
- Easier to reason about
Breaking Change
Yes — any code that mutates child.text, child.comments, or child.tags directly.
Considerations
This is a high-effort change that touches nearly every method. May need a phased approach or a compatibility layer.
Description
Currently
HConfigChild.textis mutable (modified duringnegate()), andcomments/tagsare mutable sets. This means remediation can mutate the source tree, requiringdeep_copy()to avoid side effects.Proposed Change
Make tree nodes immutable after construction:
negate()returns a new node rather than mutatingself.textcommentsandtagsbecomefrozenset(or copy-on-write)Benefits
deep_copy()becomes unnecessary in most casesBreaking Change
Yes — any code that mutates
child.text,child.comments, orchild.tagsdirectly.Considerations
This is a high-effort change that touches nearly every method. May need a phased approach or a compatibility layer.