Skip to content

Allow overloading based on TypedDict structure #3618

Closed

Description

@JukkaL

Maybe we should support overloading based on the structure of a TypedDict. For example, this could be okay, even though it's currently considered overlapping:

from typing import overload
from mypy_extensions import TypedDict

A = TypedDict('A', {'x': int})
B = TypedDict('B', {'y': str})

@overload
def f(x: A) -> int: ...
@overload
def f(x: B) -> str: ...
def f(x): ...

a: A
b: B
f(a)  # Should be int
f(b)  # Should be str

However, some overloads should probably still be considered invalid as they overlap, such as if two TypedDicts have the same keys and some value types overlap. Another special case to consider is non-total TypedDicts.

Discussion here: #3612 (comment)

Activity

  1. ilevkivskyi commented on Jul 6, 2018

    @ilevkivskyi
    Member

    This now works on master.

    However, some overloads should probably still be considered invalid as they overlap

    Yes, but these will be disabled when #5280 lands, we have a separate issue to track this.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions