Make Callable callable for typing callables

After sleeping a night over it, I came up with an alternative: CallableLike, where you would provide a template

   def myTemplate(x: int, /, y: float = 0.0) -> None: ...
   
   def myHandler( callback: CallableLike[myTemplate] ): ...

This is not completely inline, but would allow for the use of the “natural” syntax. Here, CallableLike[myTemplate] would be equivalent to CallableLikeMyTemplate as defined by

    class CallableLikeMyTemplate(Protocol):
        @staticmethod
        def __call__(x: int, /, y: float = 0.0) -> None: ...

Since I did not find a link: A similar discussion is going on here.

1 Like