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

Ternary expression with () is inferred as object #7738

Closed
jolaf opened this issue Oct 17, 2019 · 1 comment
Closed

Ternary expression with () is inferred as object #7738

jolaf opened this issue Oct 17, 2019 · 1 comment

Comments

@jolaf
Copy link
Contributor

jolaf commented Oct 17, 2019

The following code:

from typing import Sequence

def f(b: bool) -> Sequence[int]:
    return (5,) if b else ()

produces the following output:

$ python3 Test.py
$ mypy Test.py
Test.py:4: error: Incompatible return value type (got "object", expected "Sequence[int]")
Found 1 error in 1 file (checked 1 source file)
$ mypy --version
mypy 0.740
$ python3 --version
Python 3.6.8

This looks like a false positive to me.

It seems that () should be compatible with any non-empty Tuple[...] or Sequence[...]. The same goes to [].

@ilevkivskyi
Copy link
Member

Duplicate of #4975

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

2 participants