Function having return type as type variable with `Callable` bound does not allow `Callable[..., Any]` to be returned
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
Discussion: https://github.com/microsoft/pyright/discussions/10700
> The type `(...) -> Any` is the gradual form of a callable. It's the equivalent of `Any`, and it should be assignable to any callable (and vice versa), so wrapped should be assignable to the return type.
[Playground](https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCCKcANFAMICGANtZQEbUCmZAKokwGqUhkDGlAM4wAsAChxAMRRQAvFHYIuPABQAiaWrL0wAVxQATWVVoNmASnHjKxAPrAUALgo06jJnKh0I9A5WcAcmAoTOIGTMBQ4Xy4lDC4Kg7O0uZQALQAfFDSjuJQ%2BVAgTDC6IDICwirSZDZw9iiWYgWFxaUytfXiQA)
```python
from typing import Any, Callable, TypeVar
Fn = TypeVar("Fn", bound=Callable)
any_fn: Callable = lambda: None
def decorator(fn: Fn) -> Fn:
return any_fn
# ^^^^^^
# Type "(...) -> Unknown" is not assignable to return type "Fn@decorator"
# Type "(...) -> Unknown" is not assignable to type "Fn@decorator" (reportReturnType)
```
Contributor guide
Research direction
Start with the linked discussion and run the provided example in the Pyright playground to reproduce the return-type diagnostic. Trace how a Callable-bounded TypeVar is checked against Callable[..., Any], then verify that the example no longer reports reportReturnType while other return-type checks remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100