Skip to content

TypeVar argument of Tuple alias becomes Any #6704

@pdeblanc

Description

@pdeblanc

In the file foo.py:

from typing import Tuple, TypeVar

T = TypeVar('T')
TT = Tuple[T, T]


def car(items: TT) -> T:
    reveal_type(items)
    return items[0]

The revealed type is Tuple[Any, Any]:

➜  ~ git:(master) ✗ mypy --version
mypy 0.701
➜  ~ git:(master) ✗ mypy foo.py
foo.py:8: error: Revealed type is 'Tuple[Any, Any]'

I believe the correct type should have been the same as in this file bar.py:

from typing import Tuple, TypeVar

T = TypeVar('T')


def car(items: Tuple[T, T]) -> T:
    reveal_type(items)
    return items[0]

Which produces the output:

➜  ~ git:(master) ✗ mypy --version
mypy 0.701
➜  ~ git:(master) ✗ mypy bar.py
bar.py:7: error: Revealed type is 'Tuple[T`-1, T`-1]'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions