Split str.format below the cognitive-complexity threshold (0061) - #382
Merged
Merged
Conversation
StrOps::Format scanned the format string, parsed each replacement field, looked up the argument, applied attribute/index accessors and the conversion in one function (score 88). Each field is now ReplaceField, with LookupArg and ApplyAccessors as helpers. Behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LJv5o6nbcd16qaXtwhoNVG
rmorozov
marked this pull request as ready for review
October 4, 2026 03:57
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.
Requested by Ruslan · project thread
Before:
StrOps<CharT>::Formatinsrc/value_methods.cppimplements"...".format(...). One function scanned the format string, parsed each replacement field, looked up the argument, applied the.attrand[key]accessors and the!r/!sconversion. Its cognitive complexity was 88 (threshold 25), and it was kept under aNOLINTmarker.After:
Formatonly scans for braces and hands each{...}toReplaceField.ReplaceFielduses two helpers:LookupArg, which resolves a position or keyword and enforces Python's no-mixing rule for{}and{0}through aFieldNumbering, andApplyAccessors. The brace scan now uses a singledoubledflag for both{{and}}. Output, error messages and which error is reported first are all unchanged. 28 complexity markers remain. Part of docs/tasks/0061.Roles and rounds: main session plus one verifier round, which found nothing blocking.
{}!:.[]0rx. The output was byte-identical, every error path included.Red pushes: 0 so far.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LJv5o6nbcd16qaXtwhoNVG
Generated by Claude Code