Skip to content

allow overloads to be distinguished by contained type of a generic #4159

Closed
@carljm

Description

@carljm

This is a follow-up to the discussion beginning at python/typing#253 (comment)

Mypy's choice to not distinguish overload signatures by contained types rules out some natural API choices, e.g.

@overload
def map(ids: List[int]) -> Dict[int, MyObj]: ...

@overload
def map(ids: List[str]) -> Dict[str, MyObj]: ...

We've run into this limitation several times already at Instagram, and there aren't any nice workarounds for it. From a user point of view, the "empty list" rationale doesn't feel right; it seems like it should be possible to only error in specific calls with an unknown contained type.

There is some more discussion in the above-linked thread of how to handle this. In any case, I think it deserves tracking as a mypy limitation.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions