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

Literal[True, False] false positives within tuples #11701

Closed
JukkaL opened this issue Dec 10, 2021 · 0 comments · Fixed by #11709
Closed

Literal[True, False] false positives within tuples #11701

JukkaL opened this issue Dec 10, 2021 · 0 comments · Fixed by #11709
Labels
bug mypy got something wrong priority-0-high

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 10, 2021

This code generates unexpected errors:

from typing import NamedTuple, Literal, List, Tuple

C = NamedTuple("C", [("x", Literal[True, False])])

T = Tuple[Literal[True, False]]

# Incompatible types in assignment (expression has type "List[C]", variable has type "List[C]")
x: List[C] = [C(True)]

t: T

# Incompatible types in assignment (expression has type "List[Tuple[bool]]", 
# variable has type "List[Tuple[Union[Literal[True], Literal[False]]]]")
y: List[T] = [t]

The issue was introduced in #10389.

Marking as high priority since this is a regression.

cc @ethan-leba

@JukkaL JukkaL added bug mypy got something wrong priority-0-high labels Dec 10, 2021
JukkaL pushed a commit that referenced this issue Dec 14, 2021
In some places in our code bool was compared with `Union[Literal[True], Literal[False]]`.
It was later compared with each union item. And bool is not subtype of 
`Literal[True]` and `Literal[False]`.

Closes #11701
Refs #11705
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
…ython#11709)

In some places in our code bool was compared with `Union[Literal[True], Literal[False]]`.
It was later compared with each union item. And bool is not subtype of 
`Literal[True]` and `Literal[False]`.

Closes python#11701
Refs python#11705
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-0-high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant