Should `callable` narrow to `TypeIs[Callable[..., object]]` or `TypeIs[Callable]` ?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
Currently, typeshed annotates
def callable(obj: object, /) -> TypeIs[Callable[..., object]]: ...
However, for the majority of type checkers this creates discrepancy between collections.abc.Callable and builtins.callable narrowing, only ty seems to consider blank Callable as if it were Callable[..., object], whereas all other type checkers treat it as Callable[..., Any].
from typing import reveal_type, TypeIs
from collections.abc import Callable
def is_callable(arg: object) -> TypeIs[Callable]:
raise NotImplementedError
def check_callable(arg: object) -> None:
if isinstance(arg, Callable):
reveal_type(arg)
def check_callable2(arg: object) -> None:
if callable(arg):
reveal_type(arg)
def check_callable3(arg: object) -> None:
if is_callable(arg):
reveal_type(arg)
| case | isinstance(x, Callable) | is_callable | callable(x) |
|---|---|---|---|
| mypy | ERROR | (...) -> Any | <callable subtype of object> |
| pyright | (...) -> Unknown | (...) -> Unknown | (...) -> object |
| pyrefly | (...) -> Unknown | (...) -> Unknown | (...) -> object |
| ty | (...) -> object | (...) -> Any | (...) -> object |
| zuban | ERROR | (...) -> Any | <callable subtype of object> |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the builtins.callable annotation and compare it with collections.abc.Callable. Run the examples against the type-checker behaviors listed in the issue, then review the comment discussion to determine which annotation gives consistent narrowing; done means the chosen stub matches the intended behavior across the affected checkers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100