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

inferred type of "(cond and a) or b" #1477

Closed
rwbarton opened this issue May 4, 2016 · 3 comments
Closed

inferred type of "(cond and a) or b" #1477

rwbarton opened this issue May 4, 2016 · 3 comments
Labels

Comments

@rwbarton
Copy link
Contributor

rwbarton commented May 4, 2016

If cond: Bool, a: A, and b: B, then mypy thinks (cond and a) or b has type Union[bool, A, B]. But in fact the type should just be Union[A, B]. The only way (cond and a) or b can be a bool is for it to be (cond and a), and for that to be truth-y; but in that case (cond and a) would have type A, and never type bool (from cond).

@rwbarton
Copy link
Contributor Author

See also discussion at #1698.

With False and True types we could type check this as follows: with

  • cond: bool, a: A, b: B, we first have
  • cond and a: Union[falsey_type(bool), A] = Union[False, A], and then
  • (cond and a) or b: Union[truthy_type(Union[False, A]), B] = Union[A, B].

@dmoisset
Copy link
Contributor

dmoisset commented Aug 5, 2016

Just checked that my PR #1989 happens to fix this too

@gnprice gnprice added this to the 0.4.x milestone Aug 11, 2016
@ddfisher
Copy link
Collaborator

Fixed by #1989.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants