Open
Description
A function decorated with @functools.cache
loses its signature:
@functools.cache
def my_func(foo: int | list) -> str:
return str(foo)
my_func('completely', 'incorrect', 'arguments')
# Success: no issues found in 1 source file
There is an error if you try to pass an argument that isn't hashable:
my_func([])
# error: Argument 1 to "__call__" of "_lru_cache_wrapper" has
# incompatible type "list[Never]"; expected "Hashable" [arg-type]
But this completely ruins Intellisense:
I understand that the type system isn't powerful enough to express the correct semantics, which would be this:
@functools.cache
def my_func(foo: int | list) -> str:
return str(foo)
reveal_type(my_func) # Callable[[int], str]
That said, I would much rather have functioning Intellisense than a warning about unhashable inputs.