Skip to content

IndexError: list index out of range with missing typing.Annotated type #21471

@correctmost

Description

@correctmost

Crash Report

mypy 2.1.0 and master (e53693b) crash on the fuzzed snippet below.

Traceback

Traceback (most recent call last):
  File ".venv-mypy/bin/mypy", line 6, in <module>
    sys.exit(console_entry())
  File "mypy/mypy/__main__.py", line 16, in console_entry
    main()
  File "mypy/mypy/main.py", line 154, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "mypy/mypy/main.py", line 244, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "mypy/mypy/build.py", line 422, in build
    result = build_inner(
  File "mypy/mypy/build.py", line 537, in build_inner
    graph = dispatch(sources, manager, stdout, connect_threads)
  File "mypy/mypy/build.py", line 4150, in dispatch
    process_graph(graph, manager)
  File "mypy/mypy/build.py", line 4618, in process_graph
    done, still_working, results = manager.wait_for_done(graph)
  File "mypy/mypy/build.py", line 1492, in wait_for_done
    process_stale_scc(graph, next_scc, self)
  File "mypy/mypy/build.py", line 4785, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "mypy/mypy/semanal_main.py", line 91, in semantic_analysis_for_scc
    process_top_levels(graph, scc, patches)
  File "mypy/mypy/semanal_main.py", line 200, in process_top_levels
    deferred, incomplete, progress = semantic_analyze_target(
  File "mypy/mypy/semanal_main.py", line 380, in semantic_analyze_target
    analyzer.refresh_partial(
  File "mypy/mypy/semanal.py", line 694, in refresh_partial
    self.refresh_top_level(node)
  File "mypy/mypy/semanal.py", line 721, in refresh_top_level
    self.accept(d)
  File "mypy/mypy/semanal.py", line 7695, in accept
    node.accept(self)
    ~~~~~~~~~~~^^^^^^
  File "mypy/mypy/nodes.py", line 1840, in accept
    return visitor.visit_expression_stmt(self)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "mypy/mypy/semanal.py", line 5437, in visit_expression_stmt
    s.expr.accept(self)
    ~~~~~~~~~~~~~^^^^^^
  File "mypy/mypy/nodes.py", line 2607, in accept
    return visitor.visit_index_expr(self)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "mypy/mypy/semanal.py", line 6201, in visit_index_expr
    self.analyze_type_application(expr)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "mypy/mypy/semanal.py", line 6207, in analyze_type_application
    types = self.analyze_type_application_args(expr)
  File "mypy/mypy/semanal.py", line 6266, in analyze_type_application_args
    typearg = self.expr_to_unanalyzed_type(item, allow_unpack=True)
  File "mypy/mypy/semanal.py", line 7793, in expr_to_unanalyzed_type
    return expr_to_unanalyzed_type(
        node, self.options, self.is_stub_file, allow_unpack=allow_unpack
    )
  File "mypy/mypy/exprtotype.py", line 130, in expr_to_unanalyzed_type
    args[0], options, allow_new_syntax, expr, lookup_qualified=lookup_qualified
    ~~~~^^^
IndexError: list index out of range

To Reproduce

from typing import Annotated

list[Annotated[()]]

Your Environment

  • Mypy version used: 2.1.0 and e53693b
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.14.4
  • Operating system and version: Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions