fix(issue #3199): IndexError: Replacement index 0 out of range for positional args tuple - #3261
Closed
arunsoman wants to merge 2 commits into
Closed
fix(issue #3199): IndexError: Replacement index 0 out of range for positional args tuple#3261arunsoman wants to merge 2 commits into
arunsoman wants to merge 2 commits into
Conversation
Signed-off-by: Arun Soman <aarunsoman@gmail.com>
for more information, see https://pre-commit.ci
|
#3203 seems like a more comprehensive fix, but it hasn't been updated in a while. The test code in this PR seems less idiomatic too. |
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.
Fixes #3199
What
autonomous fix via
atomic-forge fix— CIE (code graph over MCP) localized the bug, generated a failing regression test, and forge's repair loop fixed the source against it.Issue
The following code triggers an
IndexErrorin astroid:AstroidError.__str__callsself.message.format(**vars(self))and only catchesValueErrorfrom that call. When the wrapped message itself contains a literal{0}(ascollections.namedtuple's ownValueErrortext does for an invalid identifier),str.formatraisesIndexError(no positional args were supplied) instead of the expectedValueError, so the internal formatting failure leaks out as a rawIndexErrorrather than astroid's own error type.Fix
astroid/exceptions.py: broadenAstroidError.__str__'s except clause fromexcept ValueError:toexcept (ValueError, IndexError, KeyError):so anystr.formatfailure on an untrusted, already-substituted message falls back to the raw message instead of crashing.How it was verified
tests/test_forge_3199.py(fails on the pre-fix code, passes on the fix)from collections import namedtuple; namedtuple('{0}', '').infer()): raisesIndexErrorbefore the fix, completes cleanly after🔨 Fixed by Forge — an autonomous, test-driven issue→PR repair engine (
atomic-forge fix <issue-url>).⭐ If you found this useful, a star on atomic-forge helps other maintainers find the tool that fixed your bug.