Skip to content

No matching overload found for function dict.__init__ when creating dict with different value types #562

Closed as duplicate

Description

@anvy2

Describe the Bug

When creating dictionaries with different type of values without manually specifying the type gives the error and the types are auto inferred based on the first value of the dict.

a = dict(key1="value1", key2=32)

This gives the error
No matching overload found for function `dict.__init__` Possible overloads: () -> None (**kwargs: str) -> None [closest match] (map: SupportsKeysAndGetItem[str, str], /) -> None (map: SupportsKeysAndGetItem[str, str], /, **kwargs: str) -> None (iterable: Iterable[tuple[str, str]], /) -> None (iterable: Iterable[tuple[str, str]], /, **kwargs: str) -> None (iterable: Iterable[list[str]], /) -> None (iterable: Iterable[list[bytes]], /) -> NonePyrefly(no-matching-overload)

and the type inferred as dict[str, str]

If I use it with

a: dict[str, Any] = dict(key1="value1", key2=32)

This works fine

Don't know if this is intentional and this is how it is supposed to work in pyrefly?

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Activity

  1. changed the title [-]No matching overload found for function `dict.__init__`[/-] [+]No matching overload found for function `dict.__init__` when creating dict with different value types[/+] on Jun 24, 2025
  2. yangdanny97 commented on Jun 24, 2025

    @yangdanny97
    Collaborator

    Thanks for reporting! Based on the error message, I think the root cause of this is #105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions