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

"Callable | Callable" not callable [misc] #17631

Open
jolaf opened this issue Aug 3, 2024 · 3 comments
Open

"Callable | Callable" not callable [misc] #17631

jolaf opened this issue Aug 3, 2024 · 3 comments
Labels
bug mypy got something wrong

Comments

@jolaf
Copy link
Contributor

jolaf commented Aug 3, 2024

The following code:

from collections.abc import Callable, Sequence
from functools import partial, reduce
from typing import cast, Any

CA = Callable[[Any], Any]
CB = Callable[[Callable[..., Any], Any], Any]

def f(s: Sequence[CA | CB]) -> CA:
    return cast(CA, reduce(lambda a, b: partial(b, a), s))

produces the following output:

test.py: note: In function "f":
test.py:9:41: error: "Callable[[Any], Any] | Callable[[Callable[..., Any], Any], Any]" not callable  [misc]
        return cast(CA, reduce(lambda a, b: partial(b, a), s))
                                            ^

This looks like a false positive to me.

$ mypy --version
mypy 1.11.1 (compiled: yes)

$ python --version
Python 3.12.3

$ lsb_release -d
No LSB modules are available.
Description:	Ubuntu 24.04 LTS
@jolaf jolaf added the bug mypy got something wrong label Aug 3, 2024
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Aug 9, 2024

This is the same as many other issues, where mypy computes join between callables to builtins.function. In this case join of [def (Any) -> Any and def (def (*Any, **Any) -> Any, Any) -> Any]. Happens to shows up in 1.11 because we now type check functools.partial more closely, but underlying issue is old. Seems tricky to turn the callsite in extract_callable_type to return a union

@bswck
Copy link

bswck commented Aug 9, 2024

I've taken on the challenge of fixing this. It's my first time working with mypy, so bear with me or let me know if someone else fixes it.

@jolaf
Copy link
Contributor Author

jolaf commented Aug 9, 2024

I've taken on the challenge of fixing this. It's my first time working with mypy, so bear with me or let me know if someone else fixes it.

Thanks!!

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

3 participants