Skip to content

Type disappears from 3-member union in error message #7241

Closed

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 Callable, TypeVar, Union

T = TypeVar("T")

def f(
    get_value: Callable[[T], Union[bool, float, str]],
) -> Callable[[T], bool]:
    return lambda t: get_value(t) == 0

def g(get_value: Callable[[T], Union[None, bool, float, str]]):
    return f(get_value)
  • What is the actual behavior/output?
a.py:11: error: Argument 1 to "f" has incompatible type "Callable[[T], Union[None, bool, float, str]]"; expected "Callable[[Any], Union[float, str]]"
  • What is the behavior/output you expect?
a.py:11: error: Argument 1 to "f" has incompatible type "Callable[[T], Union[None, bool, float, str]]"; expected "Callable[[Any], Union[bool, float, str]]"

bool is missing from the actual output.

No such error if T is a concrete type, i.e. replace T = TypeVar("T") with class T: pass.

No such error if the union returned by get_value in f has only 2 members and the union returned by get_value in g has only 3 members.

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

0.730+dev.9508e0efd2e89971f186440eac84eedbf991a4a9 (from master)

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

None

Activity

  1. ilevkivskyi commented on Jul 18, 2019

    @ilevkivskyi
    Member

    For mypy int is a subtype of float (because practicality beats purity), and thus transitively bool is a subtype of float. I don't think there is any action item here.

  2. ilevkivskyi commented on Jul 18, 2019

    @ilevkivskyi
    Member

    Actually, since there is inconsistency here, it makes sense to unify the behavior, but we already have #6168 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions