Extract duplicated import-continuation while loops into collect_import_continuation
Both parse.file_contents and identify.imports contained an almost-identical
~37-line block of while loops for collecting multi-line import statements
(parenthesised and backslash-continued forms). The only differences were:
* parse.py accesses lines via in_lines[index] (list + mutable index)
* identify.py accesses lines via next(indexed_input) (iterator)
* parse.py additionally tracks comments, nested_comments, and raw_lines
New helper in _parse_utils.py:
collect_import_continuation(line, import_string, get_next_line,
line_separator="\n")
-> (final_line, complete_import_string, extra_lines)
Both callers provide a tiny get_next_line closure that abstracts over their
respective data source. The extra_lines list carries (line, comment,
appended_with_separator) tuples so parse.py can reconstruct its per-line
side-effects; identify.py ignores it with _.
parse.py: 70-line while block -> 25-line call site (+ post-processing loop)
identify.py: 37-line while block -> 6-line call site
Co-authored-by:
DanielNoord <13665637+DanielNoord@users.noreply.github.com>
Loading
Please register or sign in to comment