Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overloading based on TypedDict structure #3618

Closed
JukkaL opened this issue Jun 27, 2017 · 1 comment
Closed

Allow overloading based on TypedDict structure #3618

JukkaL opened this issue Jun 27, 2017 · 1 comment

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 27, 2017

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)

@ilevkivskyi
Copy link
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
Projects
None yet
Development

No branches or pull requests

2 participants