Skip to content

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

Closed

Description

@jolaf

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

Activity

  1. added
    bugmypy got something wrong
    on Aug 3, 2024
  2. hauntsaninja commented on Aug 9, 2024

    @hauntsaninja
    Collaborator

    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

  3. johnslavik commented on Aug 9, 2024

    @johnslavik
    Member

    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.

  4. jolaf commented on Aug 9, 2024

    @jolaf
    ContributorAuthor

    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!!

  5. hauntsaninja commented on Jan 1, 2025

    @hauntsaninja
    Collaborator

    This was fixed in #17903

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions