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

Incompatible return type when returning empty list and annotation is Union[List] #13625

Open
matteosantama opened this issue Sep 8, 2022 · 0 comments
Labels
bug mypy got something wrong

Comments

@matteosantama
Copy link

matteosantama commented Sep 8, 2022

def fn1(data: list[int]) -> list[int]:
    return []


def fn2(data: list[int]) -> list[int] | list[str]:
    return []

mypy has no problem with the first function, but complains about the other.

error: Incompatible return value type (got "List[<nothing>]", expected "Union[List[int], List[str]]")  [return-value]
  • Mypy version used: mypy 0.971 (compiled: yes)
  • Python version used: Python 3.10.4
  • Operating system and version: macOS Monterey 12.4
@matteosantama matteosantama added the bug mypy got something wrong label Sep 8, 2022
@matteosantama matteosantama changed the title Incompatible return type when returning empty list and input is type list[A | B] Incompatible return type when returning empty list and input List[Union] or Union[List] Sep 8, 2022
@matteosantama matteosantama changed the title Incompatible return type when returning empty list and input List[Union] or Union[List] Incompatible return type when returning empty list and input is List[Union] or Union[List] Sep 8, 2022
@matteosantama matteosantama changed the title Incompatible return type when returning empty list and input is List[Union] or Union[List] Incompatible return type when returning empty list and annotation is Union[List] Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant