Skip to content

v4: Immutable config trees #224

@jtdub

Description

@jtdub

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    v4-enhancementEnhancement planned for hier_config v4.0.0

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions