-
-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Labels
enhancementNew feature or requestNew feature or request
Description
🚀 Feature request
Functions that correctly implement a callable protocol should be considered as implementing said protocol when checking for subtypes / protocol implementations. First mentioned here.
Motivation
Currently implements_protocol does not check if functions implement the protocol and returns False
when the value is a function. Since these are valid implementations of the protocol implements_protocol
should return true such that the parser can identify them as valid subtypes / implementations.
Pitch
Consider the following callable interface and two valid implementations:
class CallableInterface(Protocol):
def __call__(self, items: List[float]) -> List[float]: ...
class ImplementsCallableInterface1:
def __init__(self, batch_size: int):
self.batch_size = batch_size
def __call__(self, items: List[float]) -> List[float]:
return items
def implements_callable_interface2(items: List[float]) -> List[float]:
return items
The current behavior of def implements_protocol(value, protocol) -> bool:
is:
implements_protocol(ImplementsCallableInterface1, CallableInterface) => True
implements_protocol(implements_callable_interface2, CallableInterface) => False
It should be:
implements_protocol(ImplementsCallableInterface1, CallableInterface) => True
implements_protocol(implements_callable_interface2, CallableInterface) => True
Alternatives
?
mauvilsa
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request