summaryrefslogtreecommitdiffstats
path: root/Misc
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2024-03-29 20:06:09 (GMT)
committerGitHub <noreply@github.com>2024-03-29 20:06:09 (GMT)
commit019143fecbfc26e69800d28d2a9e3392a051780b (patch)
treee90bfafff15ff262855f7cf7e8edbfac61a68481 /Misc
parent01bd74eadbc4ff839d39762fae6366f50c1e116e (diff)
downloadcpython-019143fecbfc26e69800d28d2a9e3392a051780b.zip
cpython-019143fecbfc26e69800d28d2a9e3392a051780b.tar.gz
cpython-019143fecbfc26e69800d28d2a9e3392a051780b.tar.bz2
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.
Diffstat (limited to 'Misc')
-rw-r--r--Misc/NEWS.d/next/Library/2024-03-29-12-07-26.gh-issue-117348.WjCYvK.rst2
1 files changed, 2 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Library/2024-03-29-12-07-26.gh-issue-117348.WjCYvK.rst b/Misc/NEWS.d/next/Library/2024-03-29-12-07-26.gh-issue-117348.WjCYvK.rst
new file mode 100644
index 0000000..cd3006c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-03-29-12-07-26.gh-issue-117348.WjCYvK.rst
@@ -0,0 +1,2 @@
+Refactored :meth:`configparser.RawConfigParser._read` to reduce cyclometric
+complexity and improve comprehensibility.