GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-159684: Modernize string formatting and simplify constructs in configparser by jaraco · Pull Request #159687 · python/cpython

Conversation

@jaraco

@jaraco jaraco commented Oct 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Brings Lib/configparser.py and Lib/test/test_configparser.py up to Ruff's
default rule set, which reported 72 findings across the two files. CPython's
own Ruff configuration only selects F401 and F811 for Lib/, so nothing
here 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:

  1. f-strings (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.
  2. Simplifications — C405, C408, C414, RUF019, RUF059, F841,
    SIM102, SIM117, and parenthesizing an implicit string concatenation
    inside a list literal (ISC004) so it does not read as a missing comma.
  3. The remaining % sites that Ruff declines to autofix because the %d
    conversions are not provably integral. Converted by hand, keeping an
    explicit :d so a non-integer still raises rather than being coerced.
  4. Imports, __all__, and ClassVar (I001, RUF022, RUF012).

The last one is the only part with a design decision in it. RUF012 wants
BOOLEAN_STATES annotated ClassVar, and the obvious spelling would import
typing at runtime — which this module deliberately avoids, per the
gh-117703 note above its imports. So it adds from __future__ import annotations and imports ClassVar only under TYPE_CHECKING, the same shape
Lib/tomllib/_parser.py and Lib/importlib/metadata/__init__.py use (both
also kept in sync with a PyPI backport). python -X importtime -c "import configparser" confirms typing stays out of the import graph. Deferring
annotations also lets Iterable['ParsingError'] drop its quotes (UP037).

That does make TYPE_CHECKING a module-level name, so it joins Error in
not_exported in the check__all__ test.

C901 on ExtendedInterpolation._interpolate_some (13 > 10) is the one
finding 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 the
branching 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 py310 and py314 targets.
test_configparser, test_logging, test_collections, test___all__ and
test_pydoc pass.

NEWS entry added under Library; there is no user-visible behavior change.

  • Issue: Modernize string formatting in configparser and its test module #159684

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jaraco and others added 4 commits October 18, 2026 15:45
@jaraco @claude
pythongh-159684: Use f-strings in configparser and its tests
2db122c
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 <[email protected]>
@jaraco @claude
pythongh-159684: Simplify a few constructs in configparser and its tests
3a49bcb
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 <[email protected]>
@jaraco @claude
pythongh-159684: Convert the last percent-formatting in configparser
a63f02d
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 <[email protected]>
@jaraco @claude
pythongh-159684: Clear the remaining Ruff findings in configparser
105bdde
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 <[email protected]>
@bedevere-app bedevere-app Bot mentioned this pull request Oct 18, 2026
Modernize string formatting in configparser and its test module #159684
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 18, 2026
@jaraco @claude
pythongh-159684: Add a NEWS entry
c45a20e
Co-Authored-By: Claude Opus 5 <[email protected]>
@jaraco
jaraco enabled auto-merge (squash) October 18, 2026 21:27
terryjreedy
terryjreedy reviewed Oct 19, 2026
View reviewed changes
Comment thread Lib/test/test_configparser.py
config_string = f"""\
[Foo Bar]
foo{0[0]}bar1
foo{self.delimiters[0]}bar1

@terryjreedy terryjreedy Oct 19, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good name is better than 0[0], but the repetitive long indexed name is better and worse. Add a human
touch by adding `open, close = self.delimiters at the top and then replace s.d[0] and s.d[1] with open and close.

Same where appropriate for other methods. Need to be cognizant that some calls to newconfig change delimiters. (This seems to be the main use of the method.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
StanFromIreland
StanFromIreland reviewed Oct 19, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2026-10-18-16-09-24.gh-issue-159684.VHVYjVuE.rst

@StanFromIreland StanFromIreland Oct 19, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think refactors need a news entry.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jaraco
jaraco merged commit 1b72935 into python:main Oct 21, 2026
148 of 152 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@terryjreedy terryjreedy terryjreedy left review comments
@StanFromIreland StanFromIreland StanFromIreland left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jaraco @terryjreedy @StanFromIreland
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.