Skip to content

Generic functions are not subtypes of generic protocols #936

@ndmitchell

Description

@ndmitchell

Describe the Bug

from typing import *

_C = TypeVar("_C")

class _Decorator(Protocol):
    def __call__(self, fn: _C) -> _C: ...


def api() -> _Decorator:
    def _impl(fn: _C) -> _C:
        ...
    return _impl # E: Returned type `[_C](fn: _C) -> _C` is not assignable to declared return type `_Decorator`

Sandbox Link

https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoBUAUEQPoDCUAvFACqICmAagIYgAUARBZwJQkBjADYsAzqKikAIgwG4WMXOwAK4RXKG8AXESh6oAEwbBJpASyFDSpdqIZDgAGijAUWyeV5QAtAD4P7gB0wSRERiYsyOxefpIyciAKuDr6hsaSWAhC7K7uFDH%2BFCmp%2BsGBuvogDDAAriAoGdhCREA&version=3.12

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

UserBugs reported by external users that should be prioritisedhelion

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions