basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

`callable` function is special-cased and doesn't narrow functions properly

Open DetachHead opened this issue 1 year ago • 0 comments

from typing import Callable, cast, TypeGuard

# mypy: disallow-any-explicit=false

value: object
if callable(value):
    cast(Callable[[], None], value) # error: non overlapping cast


# if we copy its signature from typeshed, it works:
def callable2(obj: object, /) -> TypeGuard[Callable[..., object]]: ... #type:ignore[empty-body]
if callable2(value):
    cast(Callable[[], None], value) # no error

playground

DetachHead avatar Mar 22 '24 08:03 DetachHead