Skip to content

v4: Unify negation rules into single NegationRule with strategy enum #220

@jtdub

Description

@jtdub

Description

The current negation system has three separate rule types and an implicit priority chain in negate():

  1. NegationDefaultWithRule (replace with fixed string)
  2. NegationDefaultWhenRule (use default form)
  3. NegationSubRule (regex substitution)
  4. swap_negation() (fallback)

These are three different Pydantic models, three fields on HConfigDriverRules, and the precedence is encoded in method ordering rather than being explicit.

Proposed Change

Unify into a single rule type:

class NegationStrategy(Enum):
    REPLACE = auto()      # was negate_with
    DEFAULT = auto()      # was negation_default_when
    REGEX_SUB = auto()    # was negation_sub

class NegationRule(BaseModel):
    match_rules: tuple[MatchRule, ...]
    strategy: NegationStrategy
    value: str = ""       # replacement text or regex pattern
    replace: str = ""     # for REGEX_SUB strategy

Single negation_rules field on HConfigDriverRules. First matching rule wins.

Benefits

  • Collapses three rule types and three driver fields into one
  • Precedence is explicit (list order) rather than implicit (method ordering)
  • Easier to understand and extend

Breaking Change

Yes — all existing negate_with, negation_default_when, and negation_sub rules must be migrated.

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