Skip to content

False error in conditional expression returning union #6898

Closed
@ghost

Description

  • Are you reporting a bug, or opening a feature request?

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.
from typing import TypeVar, Union


T = TypeVar("T")


def get_or_str(value: T) -> Union[str, T]:
    return value


def f(b: bool) -> Union[str, bool]:
    return "" if b else get_or_str(True)
  • What is the actual behavior/output?

a.py:12: error: Argument 1 to "get_or_str" has incompatible type "bool"; expected "str"

  • What is the behavior/output you expect?

No error.

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

0.710+dev.5f08ccf029aa3046b15e1afc60743ba692e4758d (from master)

  • What are the mypy flags you are using? (For example --strict-optional)

None

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions