Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Incompatible return value type (got "function", expected "Callable[..., Any]") #12053

Closed
gcaria opened this issue Jan 24, 2022 · 2 comments
Closed
Labels
bug mypy got something wrong topic-join-v-union Using join vs. using unions topic-ternary-expression a if b else c

Comments

@gcaria
Copy link

gcaria commented Jan 24, 2022

import glob
from typing import Callable, List


def fun1(b: str) -> List[str]:
    return ["a", "b"] + [b]


def fun(a: str) -> Callable:
    return fun1 if a == "hello" else glob.glob

Running mypy (v 0.931) on this file gives:

error: Incompatible return value type (got "function", expected "Callable[..., Any]")  [return-value]

Crossposting from stackoverflow where an answer suggests that this problem is limited to using the ternary operator, but a bug nevertheless.

@gcaria gcaria added the bug mypy got something wrong label Jan 24, 2022
@erictraut
Copy link

This can be added to the increasingly long list of issues caused by mypy's use of join rather than union. See #12009.

@AlexWaygood
Copy link
Member

I'm closing this as a duplicate of #10740, as it's nearly exactly the same behaviour on display

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug mypy got something wrong topic-join-v-union Using join vs. using unions topic-ternary-expression a if b else c
Projects
None yet
Development

No branches or pull requests

4 participants