python / python/mypy

The different type (`str`) of unpacked inner dictionary items from the type (`int`) of outer dictionary items gets error

Open
#20,705 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-type-context
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

*Memo:

  • mypy test.py
  • Python 3.14.0
  • mypy 1.19.1

The different type (str) of unpacked inner list items from the type (int) of outer list items doesn't get error as shown below:

v = [0, 1, *['a', 'b']] # No error

The different type (str) of unpacked inner dictionary items from the type (int) of outer dictionary items gets the error as shown below:

v = {0: 1, **{'a':'b'}} # Error

error: Cannot infer value of type parameter "KT" of

In additioin, if the types of keys in an inter and outer dictionary are the same, error doesn't occur as shown below:

v1 = {0: 1, **{2:'b'}}
v2 = {'0': 1, **{'a':'b'}}
# No error

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 minimal examples in test.py and run mypy on Python 3.14.0 to reproduce the differing diagnostics for list and dictionary unpacking. Trace the type inference path for the shown dictionary cases and add or update a focused regression test; done means the intended behavior is covered consistently without regressing the existing same-key-type cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
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.