]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-117348: Refactored RawConfigParser._read for similicity and comprehensibility...
authorJason R. Coombs <jaraco@jaraco.com>
Fri, 29 Mar 2024 20:06:09 +0000 (16:06 -0400)
committerGitHub <noreply@github.com>
Fri, 29 Mar 2024 20:06:09 +0000 (16:06 -0400)
commit019143fecbfc26e69800d28d2a9e3392a051780b
treee90bfafff15ff262855f7cf7e8edbfac61a68481
parent01bd74eadbc4ff839d39762fae6366f50c1e116e
gh-117348: Refactored RawConfigParser._read for similicity and comprehensibility (#117372)

* Extract method for _read_inner, reducing complexity and indentation by 1.

* Extract method for _raise_all and yield ParseErrors from _read_inner.

Reduces complexity by 1 and reduces touch points for handling errors in _read_inner.

* Prefer iterators to splat expansion and literal indexing.

* Extract method for _strip_comments. Reduces complexity by 7.

* Model the file lines in a class to encapsulate the comment status and cleaned value.

* Encapsulate the read state as a dataclass

* Extract _handle_continuation_line and _handle_rest methods. Reduces complexity by 8.

* Reindent

* At least for now, collect errors in the ReadState

* Check for missing section header separately.

* Extract methods for _handle_header and _handle_option. Reduces complexity by 6.

* Remove unreachable code. Reduces complexity by 4.

* Remove unreachable branch

* Handle error condition early. Reduces complexity by 1.

* Add blurb

* Move _raise_all to ParsingError, as its behavior is most closely related to the exception class and not the reader.

* Split _strip* into separate methods.

* Refactor _strip_full to compute the strip just once and use 'not any' to determine the factor.

* Replace use of 'sys.maxsize' with direct computation of the stripped value.

* Extract has_comments as a dynamic property.

* Implement clean as a cached property.

* Model comment prefixes in the RawConfigParser within a prefixes namespace.

* Use a regular expression to search for the first match.

Avoids mutating variables and tricky logic and over-computing all of the starts when only the first is relevant.
Lib/configparser.py
Misc/NEWS.d/next/Library/2024-03-29-12-07-26.gh-issue-117348.WjCYvK.rst [new file with mode: 0644]