Skip to content

fix(issue #3199): IndexError: Replacement index 0 out of range for positional args tuple - #3261

Closed
arunsoman wants to merge 2 commits into
pylint-dev:mainfrom
arunsoman:forge/fix-issue-3199
Closed

fix(issue #3199): IndexError: Replacement index 0 out of range for positional args tuple#3261
arunsoman wants to merge 2 commits into
pylint-dev:mainfrom
arunsoman:forge/fix-issue-3199

Conversation

@arunsoman

Copy link
Copy Markdown

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

IndexError: Replacement index 0 out of range for positional args tuple

The following code triggers an IndexError in astroid:

a = namedtuple('{0}', '')

AstroidError.__str__ calls self.message.format(**vars(self)) and only catches ValueError from that call. When the wrapped message itself contains a literal {0} (as collections.namedtuple's own ValueError text does for an invalid identifier), str.format raises IndexError (no positional args were supplied) instead of the expected ValueError, so the internal formatting failure leaks out as a raw IndexError rather than astroid's own error type.

Fix

astroid/exceptions.py: broaden AstroidError.__str__'s except clause from except ValueError: to except (ValueError, IndexError, KeyError): so any str.format failure on an untrusted, already-substituted message falls back to the raw message instead of crashing.

How it was verified

  • CIE-generated regression test: tests/test_forge_3199.py (fails on the pre-fix code, passes on the fix)
  • repair rounds: 1 failures: 1 -> 0
  • repaired file(s): astroid/exceptions.py
  • independently re-verified with a standalone repro script against both the pre-fix and post-fix commit (from collections import namedtuple; namedtuple('{0}', '').infer()): raises IndexError before the fix, completes cleanly after

Fixed by Forge

🔨 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.

Arun Soman and others added 2 commits August 30, 2026 18:54
@correctmost

Copy link
Copy Markdown

#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.

@cdce8p cdce8p closed this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError: Replacement index 0 out of range for positional args tuple

3 participants