KEMBAR78
If list item has incompatible type, display expected type · Issue #3499 · python/mypy · GitHub
Skip to content

If list item has incompatible type, display expected type #3499

@JukkaL

Description

@JukkaL

Currently this program produces the error List item 0 has incompatible type "float":

from typing import List
def f(x: List[int]) -> None: ...
f([1.0])  # Error

This can be confusing, especially if the types are more complicated. The message doesn't tell what is expected, and the function definition can be hard to find, for example if it's in a stub. A better message would be something like this:

prog.py:3: error: List item 0 has incompatible type "float" (expected "int")

The same issue may also applies to dictionaries:

prog.py:3: error: Dict entry 0 has incompatible type "int": "int"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions