Repository navigation
Conversation
Convert the remaining printf-style and str.format() call sites in Lib/configparser.py and Lib/test/test_configparser.py to f-strings (Ruff UP030, UP031, UP032), rewrapping the lines that would otherwise exceed 79 columns. No behavior change; the rendered strings are identical. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Apply the straightforward simplifications Ruff reports for these two modules: redundant list() calls (C408, C414), a literal set (C405), a key check that get() already covers (RUF019), an unpacked value that is never used (RUF059), an unused assertRaises binding (F841), collapsible if statements (SIM102) and nested with statements (SIM117). Also parenthesize an implicit string concatenation inside a list literal (ISC004) so it is not mistaken for a missing comma. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Ruff leaves these UP031 sites alone because the %d conversions are not provably integral, so convert them by hand, keeping the explicit :d format spec so a non-integer still raises rather than being coerced. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sort the imports (I001) and __all__ (RUF022), and annotate the mutable class attributes as ClassVar (RUF012). The ClassVar annotation would otherwise mean importing typing at runtime, which this module avoids, so defer annotations with __future__ instead and import ClassVar only under TYPE_CHECKING, as tomllib and importlib.metadata do. Deferring annotations also lets ParsingError be referenced unquoted (UP037). ExtendedInterpolation._interpolate_some gets an explicit noqa: C901, tagged with pythongh-159686, which records why the complexity is inherent to the interpolation grammar and what a refactoring might look like. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings
Lib/configparser.pyandLib/test/test_configparser.pyup to Ruff'sdefault rule set, which reported 72 findings across the two files. CPython's
own Ruff configuration only selects
F401andF811forLib/, so nothinghere was failing; the motivation is readability plus keeping the module
convergent with its PyPI backport, which lints with the defaults and would
otherwise need a per-file exemption for exactly these two files
(jaraco/configparser#73).
Four commits, each reviewable on its own:
UP030,UP031,UP032) — the autofixable conversions,with the lines that would have exceeded 79 columns rewrapped by hand. The
rendered strings are unchanged;
%%escapes collapse to%as the%operator did.
C405,C408,C414,RUF019,RUF059,F841,SIM102,SIM117, and parenthesizing an implicit string concatenationinside a list literal (
ISC004) so it does not read as a missing comma.%sites that Ruff declines to autofix because the%dconversions are not provably integral. Converted by hand, keeping an
explicit
:dso a non-integer still raises rather than being coerced.__all__, andClassVar(I001,RUF022,RUF012).The last one is the only part with a design decision in it.
RUF012wantsBOOLEAN_STATESannotatedClassVar, and the obvious spelling would importtypingat runtime — which this module deliberately avoids, per thegh-117703note above its imports. So it addsfrom __future__ import annotationsand importsClassVaronly underTYPE_CHECKING, the same shapeLib/tomllib/_parser.pyandLib/importlib/metadata/__init__.pyuse (bothalso kept in sync with a PyPI backport).
python -X importtime -c "import configparser"confirmstypingstays out of the import graph. Deferringannotations also lets
Iterable['ParsingError']drop its quotes (UP037).That does make
TYPE_CHECKINGa module-level name, so it joinsErrorinnot_exportedin thecheck__all__test.C901onExtendedInterpolation._interpolate_some(13 > 10) is the onefinding not fixed. It is a measurement, not a defect, and no small edit
satisfies it, so it gets
# noqa: C901 # gh-159686; gh-159686 records why thebranching is inherent to the interpolation grammar and sketches a possible
refactoring, so the suppression is documented rather than silent.
With all four applied, both CPython's Ruff configuration and the default rule
set report no findings for either file, at
py310andpy314targets.test_configparser,test_logging,test_collections,test___all__andtest_pydocpass.NEWS entry added under
Library; there is no user-visible behavior change.🤖 Generated with Claude Code