Skip to content

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

Closed
@jolaf

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

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