Skip to content

Support narrowing using TypeGuard #117

@dhruvmanila

Description

@dhruvmanila

Add support for narrowing on TypeGuard and TypeIs:

This will in turn support builtins.callable:

Add support for narrowing on builtins.callable, requires TypeIs support.

builtins.pyi:

def callable(obj: object, /) -> TypeIs[Callable[..., object]]: ...

Otherwise, it causes a few false positives, like:

def _(a: Any | None) -> None:
    # /private/tmp/mypy_primer/projects/bidict/bidict/_iter.py:50:34: Object of type `None` is not callable
    if callable(a):
        a()  # red-knot: Object of type `None` is not callable [lint:call-non-callable]
        reveal_type(a)  # revealed_type: Any | None

Metadata

Metadata

Assignees

Labels

help wantedContributions especially welcomenarrowingrelated to flow-sensitive type narrowingtyping semanticstyping-module features, spec compliance, etc

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions