You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have a use case in which (AFAICT) mypy is not able to deal with the exclusive options given by a Union.
Are you reporting a bug, or opening a feature request?
A bug.
Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
ariciputi
changed the title
Mypy can't deal with exclusice options implied by a Union
Mypy can't deal with exclusive options implied by a Union
Jul 26, 2019
Thanks for the report! It might be a reasonable for mypy to infer a narrower type after testing a boolean. Say, after if bool_value: return (or if bool_value is True: return) we might infer Literal[False] as the type of bool_value. This seems closely related to #6366 but a slightly different use case.
I think this is a duplicate of #6113 (treating bool as equivalent to Union[Literal[True], Literal[False]]). I am going to raise priority there and update the title.
Hi,
I have a use case in which (AFAICT)
mypy
is not able to deal with the exclusive options given by aUnion
.A bug.
Here it is a minimal code snippets:
example.py:10: error: Unsupported right operand type for in ("Union[bool, Collection[str]]")
This is a perfectly valid Python code, so mypy shouldn't complain.
Haven't tried
None
Hope you can help.
The text was updated successfully, but these errors were encountered: