Skip to content

overload with tuples of different arity #5302

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

Closed
wabu opened this issue Jun 30, 2018 · 1 comment
Closed

overload with tuples of different arity #5302

wabu opened this issue Jun 30, 2018 · 1 comment

Comments

@wabu
Copy link

wabu commented Jun 30, 2018

When using overload, I realized that it wrongly does not complain about type mismatches as soon as one defines overloaded versions with Tuple of different arites. Here comes a minimal example:

from typing import Tuple, TypeVar, overload, List, Any

T = TypeVar('T')
_1 = TypeVar('_1')
_2 = TypeVar('_2')
_3 = TypeVar('_3')

@overload
def foo(bar: List[T], baz: List[T]) -> List[T]:
    pass

@overload
def foo(bar: Tuple[_1, _2], baz: Tuple[_1, _2]) -> Tuple[_1, _2]:
    pass

@overload
def foo(bar: Tuple[_1, _2, _3], baz: Tuple[_1, _2, _3]) -> Tuple[_1, _3]:
    pass

def foo(bar: Any, baz: Any) -> Any:
    return (bar[0], baz[-1])

# good call to foo
d: Tuple[int, str] = foo((1, 'a'), (2, 'a'))

# should fails, but currently only fails if Tuple[_1, _2, _3] overload is removed
e: Tuple[int, str] = foo((1, 'a'), (2, 3)) 
  • mypy 0.610
  • Python 3.6.5
@emmatyping
Copy link
Member

This fails as I would expect on master, I presume due to #5163.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants