Skip to content

Function having return type as type variable with Callable bound does not allow Callable[..., Any] to be returned #10702

@Glinte

Description

@Glinte

Discussion: #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

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions