ty icon indicating copy to clipboard operation
ty copied to clipboard

Incorrect top materialization of `Callable` types

Open AlexWaygood opened this issue 2 months ago • 0 comments

Summary

Because of this TODO, we currently believe that the top materialization of Callable[..., Any] is Callable[[], object]. But that's not correct, and it means that we infer bad types when inferring the narrowed type after callable() calls, for example (because callable() returns TypeIs, and following https://github.com/astral-sh/ruff/pull/20591 we implicitly convert TypeIs types to their top materializations):

from typing import Any
from typing import Callable

def f(x: Callable[..., Any] | None):
    if callable(x):
        reveal_type(x)  # `((...) -> Any) & (() -> object)` on `main`
                        # should be `((...) -> Any`

https://play.ty.dev/6f8a8a34-c7e9-41b5-b211-7701a3e905ad

We should fix this.

Version

No response

AlexWaygood avatar Oct 23 '25 20:10 AlexWaygood