Skip to content

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

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

Closed
ghost opened this issue Jul 18, 2019 · 2 comments
Closed

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

ghost opened this issue Jul 18, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 18, 2019

  • 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

@ilevkivskyi
Copy link
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.

@ilevkivskyi
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant