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:
- Banner detection and aggregation
- Indentation analysis and adjustment
- 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.
Description
_load_from_string_lines()inconstructors.py:223-305is 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, andmost_recent_item.It handles three distinct responsibilities in a single function:
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_analyze_indent()and_adjust_indent()as they already areThis would make the parsing logic easier to test in isolation and easier to extend for new platform quirks.