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

False positive: literals in unions #11414

Closed
Tinche opened this issue Oct 31, 2021 · 2 comments
Closed

False positive: literals in unions #11414

Tinche opened this issue Oct 31, 2021 · 2 comments
Labels
bug mypy got something wrong

Comments

@Tinche
Copy link
Contributor

Tinche commented Oct 31, 2021

Bug Report

Mypy reports an error where it shouldn't. Sample code included below.

To Reproduce

from typing import Literal, Union


def test() -> Union[tuple[Literal[1], str], tuple[Literal[2], int]]:
    return 1, ""

Expected Behavior

The code should successfully type-check.

Actual Behavior

Mypy does not successfully type check the code, reporting:

error: Incompatible return value type (got "Tuple[int, str]", expected "Union[Tuple[Literal[1], str], Tuple[Literal[2], int]]")

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none (defaults)
  • Python version used: 3.9.7
  • Operating system and version: Ubuntu 21.10
@Tinche Tinche added the bug mypy got something wrong label Oct 31, 2021
@sobolevn
Copy link
Member

Please, check if https://github.com/python/mypy/pull/11236/files solves your issue!

@Tinche
Copy link
Contributor Author

Tinche commented Oct 31, 2021

@sobolevn It does! Thanks, closing this.

@Tinche Tinche closed this as completed Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants