Skip to content

Refactor _load_from_string_lines() to reduce complexity #186

@jtdub

Description

@jtdub

Description

_load_from_string_lines() in constructors.py:223-305 is a high-complexity function (flagged with # noqa: C901) that tracks 8 mutable state variables: indent_adjust, end_indent_adjust, temp_banner, banner_end_lines, banner_end_contains, in_banner, current_section, and most_recent_item.

It handles three distinct responsibilities in a single function:

  1. Banner detection and aggregation
  2. Indentation analysis and adjustment
  3. Per-line substitution and hierarchy construction

Proposed Improvement

Refactor into a stateful parser class or extract into well-named helper functions:

  • _process_banner_line() — handle in-banner state
  • _detect_banner_start() — detect banner start markers
  • _normalize_line() — handle whitespace normalization and per-line substitution
  • Keep _analyze_indent() and _adjust_indent() as they already are

This would make the parsing logic easier to test in isolation and easier to extend for new platform quirks.

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