You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes#5453
The issue proposed an interesting idea. Allow callables as subtypes of protocols with `__call__`. IMO this is not just reasonable and type safe, but is also more clear that the extended callable syntax in `mypy_extensions`. For example:
```python
class Combiner(Protocol):
def __call__(self, *vals: bytes, maxlen: Optional[int] = None) -> List[bytes]: ...
def batch_proc(data: Iterable[bytes], cb_results: Combiner) -> bytes:
...
```
The callback protocols:
* Have cleaner familiar syntax in contrast to `Callable[[VarArg(bytes), DefaultNamedArg(Optional[int], 'maxlen')], List[bytes]]` (compare to above)
* Allow to be more explicit/flexible about binding of type variables in generic callbacks (see tests for examples)
* Support overloaded callbacks (this is simply impossible with the current extended callable syntax)
* Are easy to implement
If this will get some traction, I would actually propose to deprecate extended callable syntax in favor of callback protocols.
0 commit comments