Pyright: Tuple with generic var incorrectly inferred

Created on 19 May 2020  路  3Comments  路  Source: microsoft/pyright

Describe the bug
Thanks for developing this awesome tool!
Pyright seems to produce wrong diagnosis reports when type checking the following code snippet. While mypy finds no issue in the code, pyright complains:

error: Expression of type "Tuple[Literal[False], Literal['why it is invalid']]" cannot be assigned to return type "Tuple[str]" Tuple size mismatch; expected 1 but got 2 (reportGeneralTypeIssues)

and it looks like the ValidationResult[str] has been incorrectly inferred...

To Reproduce
Type check the following code snippet using mypy and pyright.

Expected behavior
ValidationResult[str] is inferred to Tuple[bool, Optional[str]] instead of Tuple[str]

Screenshots or Code
Code snippet:

from typing import Tuple, Optional, TypeVar

T = TypeVar('T')

ValidationResult = Tuple[bool, Optional[T]]

def foo() -> ValidationResult[str]:
    return False, 'why it is invalid'

VS Code extension or command-line
Are you running pyright as a VS Code extension or a command-line tool?

  • Both

Which version?

  • VSCode Pyright version: 1.1.37
  • Pyright command line tool version: 1.1.37
addressed in next version bug

All 3 comments

Thanks for the bug report. This will be fixed in the next version of pyright. The code was not correctly dealing with type aliases that consisted of partially-specialized classes.

This is now addressed in Pyright 1.1.38, which I just published.

Great! Thanks for the efficient fix!

Was this page helpful?
0 / 5 - 0 ratings