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

isinstance/issubclass don't properly handle tuple of tuples #2994

Closed
pkch opened this issue Mar 14, 2017 · 0 comments
Closed

isinstance/issubclass don't properly handle tuple of tuples #2994

pkch opened this issue Mar 14, 2017 · 0 comments

Comments

@pkch
Copy link
Contributor

pkch commented Mar 14, 2017

This code:

def f(x: Union[int, str, List, Tuple]) -> None:
    if isinstance(x, (str, (int, tuple))):
        print(x[1])

results in error: Argument 2 to "isinstance" has incompatible type "Tuple[str, Tuple[List[_T], Tuple[_T_co, ...]]]"; expected "Union[type, Tuple[type, ...]]".

Python 2 and 3 allow to put nested tuples as the second argument to isinstance, but neither typeshed nor mypy are aware of it. The typeshed needs to be fixed first (python/typeshed#997), but then still some logic needs to be updated inside mypy (otherwise, it results in internal error since it doesn't expect nested tuples; it should instead result in an type validation error).

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

1 participant