Skip to content

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

Description

@correctmost

Steps to reproduce

The following code triggers an IndexError in astroid:

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

I found the bug during a local fuzzing run.

Current behavior

Traceback (most recent call last):
  File "pylint/pylint/checkers/utils.py", line 1376, in safe_infer
    value = next(infer_gen)
  File "astroid/astroid/nodes/node_ng.py", line 140, in infer
    for result in self._explicit_inference(
                  ~~~~~~~~~~~~~~~~~~~~~~~~^
        self,  # type: ignore[arg-type]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        context,
        ^^^^^^^^
    ):
    ^
  File "astroid/astroid/inference_tip.py", line 67, in inner
    raise e from None
  File "astroid/astroid/inference_tip.py", line 64, in inner
    result = _cache[func, node, context] = list(func(node, context))
                                                ~~~~^^^^^^^^^^^^^^^
  File "astroid/astroid/brain/brain_namedtuple_enum.py", line 229, in infer_named_tuple
    raise UseInferenceDefault("ValueError: " + str(exc)) from exc
                                               ~~~^^^^^
  File "astroid/astroid/exceptions.py", line 67, in __str__
    return self.message.format(**vars(self))
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
IndexError: Replacement index 0 out of range for positional args tuple

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "pylint/pylint/utils/ast_walker.py", line 87, in walk
    callback(astroid)
    ~~~~~~~~^^^^^^^^^
  File "pylint/pylint/checkers/base/name_checker/checker.py", line 451, in visit_assignname
    utils.safe_infer(assign_type.value) if assign_type.value else None
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "pylint/pylint/checkers/utils.py", line 1380, in safe_infer
    raise AstroidError from e
astroid.exceptions.AstroidError

Expected behavior

No crash

Version info

86664181
pylint-dev/pylint@a219ca322
Python 3.14.6

The crash also affects Pylint 4.0.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions