Summary
In this example, inference of the lambda parameters and return type work with the non-overloaded function but fails with the overloaded one even though the overload is correctly resolved (as evidenced by the outer reveal_types)
from collections.abc import Callable
from typing import overload, reveal_type
@overload
def f(a: str, b: Callable[[int], str], /) -> str: ...
@overload
def f(a: bytes, b: Callable[[int], bytes], /) -> bytes: ...
def f(a, b, /): return a
def g[T: (str, bytes)](a: T, b: Callable[[int], T], /) -> T: return a
reveal_type( # Revealed type: `str`
f("", reveal_type(lambda x: str(x) * x)) # Revealed type: `(x) -> Unknown`
)
reveal_type( # Revealed type: `bytes`
f(b"", reveal_type(lambda x: x.to_bytes(1))) # Revealed type: `(x) -> Unknown`
)
reveal_type( # Revealed type: `str`
g("", reveal_type(lambda x: str(x) * x)) # Revealed type: `(x: int) -> str`
)
reveal_type( # Revealed type: `bytes`
g(b"", reveal_type(lambda x: x.to_bytes(1))) # Revealed type: `(x: int) -> bytes`
)
Playground
Version
ty 0.0.40
Summary
In this example, inference of the lambda parameters and return type work with the non-overloaded function but fails with the overloaded one even though the overload is correctly resolved (as evidenced by the outer
reveal_types)Playground
Version
ty 0.0.40