Skip to content

Can't infer type of input (dict) and think it is an "object". #4588

@hvnsweeting

Description

@hvnsweeting
  • Are you reporting a bug, or opening a feature request?
    Bug

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

from typing import Dict

idata = {'a': 1, 'prices': {'first_50': 1230, 'from_51_to_100': 1530, 'above_100': 1786}}

def dictin(names):
    # type: (Dict) -> int
    return 5


if __name__ == "__main__":
    dictin(idata['prices'])
  • What is the actual behavior/output?
$ mypy dictin.py
dictin.py:11: error: Argument 1 to "dictin" has incompatible type "object"; expected "Dict[Any, Any]"
  • What is the behavior/output you expect?
    Know that I passed a correct dict, thus no error.

If I remove the key:value 'a': 1, the check passed without any error.

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?
    Latest one
 mypy --version
mypy 0.570-dev-b0af822a79465a93d55e67b5aea74551a63c08f4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions