python / python/mypy

Combing two special mapping functions confuses Mypy

Open
#15,738 0 comments 0 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

Combing two special mapping functions confuses Mypy (and Pylance) and I can't fix the error using type annotations.

To Reproduce

code

Actual Behavior

main.py:70: error: Cannot infer type argument 1 of <dict>  [misc]
main.py:70: note: Try assigning the literal to a variable annotated as dict[<key>, <val>]
main.py:79: note: Revealed type is "builtins.dict[Any, Any]"
main.py:84: error: Unpacked dict entry 0 has incompatible type "dict[Info[str], Info[str]]"; expected "SupportsKeysAndGetItem[Unique[str] | str, Unique[str] | str]"  [dict-item]
main.py:88: error: Unpacked dict entry 1 has incompatible type "dict[Unique[str], Unique[str]]"; expected "SupportsKeysAndGetItem[Unique[str] | str, Unique[str] | str]"  [dict-item]
main.py:92: error: Unpacked dict entry 2 has incompatible type "dict[Info[str], Info[str]]"; expected "SupportsKeysAndGetItem[Unique[str] | str, Unique[str] | str]"  [dict-item]
Found 4 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.4.1
  • Mypy command-line flags: /
  • Mypy configuration options from mypy.ini (and other config files): /
  • Python version used: 3.11

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 linked reproduction and its main.py using mypy 1.4.1, then inspect the type inference and dictionary-unpacking paths involved in the reported errors. Done means the reproduction no longer reports the four errors while preserving the expected inferred types.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.