https://github.com/python/cpython
Revision 019143fecbfc26e69800d28d2a9e3392a051780b authored by Jason R. Coombs on 29 March 2024, 20:06:09 UTC, committed by GitHub on 29 March 2024, 20:06:09 UTC
* 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.
1 parent 01bd74e
History
Tip revision: 019143fecbfc26e69800d28d2a9e3392a051780b authored by Jason R. Coombs on 29 March 2024, 20:06:09 UTC
gh-117348: Refactored RawConfigParser._read for similicity and comprehensibility (#117372)
Tip revision: 019143f
File Mode Size
.azure-pipelines
.devcontainer
.github
Android
Doc
Grammar
Include
Lib
Mac
Misc
Modules
Objects
PC
PCbuild
Parser
Programs
Python
Tools
iOS
.coveragerc -rw-r--r-- 526 bytes
.editorconfig -rw-r--r-- 214 bytes
.gitattributes -rw-r--r-- 3.9 KB
.gitignore -rw-r--r-- 3.1 KB
.mailmap -rw-r--r-- 175 bytes
.pre-commit-config.yaml -rw-r--r-- 1.1 KB
.readthedocs.yml -rw-r--r-- 1014 bytes
LICENSE -rw-r--r-- 13.5 KB
Makefile.pre.in -rw-r--r-- 116.4 KB
README.rst -rw-r--r-- 8.6 KB
aclocal.m4 -rw-r--r-- 23.7 KB
config.guess -rwxr-xr-x 48.2 KB
config.sub -rwxr-xr-x 36.1 KB
configure -rwxr-xr-x 857.2 KB
configure.ac -rw-r--r-- 239.3 KB
install-sh -rwxr-xr-x 15.0 KB
pyconfig.h.in -rw-r--r-- 53.5 KB

README.rst

back to top