python / python/mypy

[1.14 regression] Unpacking an iterator converts the inner type to `Any`

Open
#18,320 11 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

Unpacking an iterator into a list produces a list[Any] instead of the more specific type. This worked correctly in mypy 1.13.0 but no longer works in 1.14.0.

To Reproduce

from typing import reveal_type
x = [1, 2]
reveal_type([*reversed(x)])
y = [3, 4]
reveal_type([*map(str, y)])

Expected Behavior

In mypy 1.13.0:

x.py:3: note: Revealed type is "builtins.list[builtins.int]"
x.py:5: note: Revealed type is "builtins.list[builtins.str]"

Actual Behavior

In mypy 1.14.0:

x.py:3: note: Revealed type is "builtins.list[Any]"
x.py:5: note: Revealed type is "builtins.list[Any]"

Your Environment

  • Mypy version used: 1.14.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.13.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Python reproducer and compare the reveal_type output between mypy 1.13.0 and 1.14.0, focusing on list unpacking from reversed and map. Done means mypy reports list[int] and list[str] rather than list[Any] for those two expressions without special flags.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.