El sáb, 19 jun 2021 a las 20:20, S Pradeep Kumar (<gohanpra@gmail.com>) escribió:
<snip>
# Questions

In my limited exploration above, I did not find callables that were given `Callable[..., Any]` for the lack of things like named parameters, default values, or `*args: int`. This suggests that the shorthand syntax `(int, bool) -> str` might cover almost all of our use cases. [2]

+ Do we have real-world examples where a Callable type was given `Callable[..., Any]` because it could not be expressed with positional-only parameters or ParamSpec or TypeVarTuple?

+ Do we have real-world examples of untyped Python code where a callable is called with named parameters? This is the remaining category (3) where features beyond shorthand syntax might potentially be useful.

Given that overloads are unlikely to be represented in our callable syntax, as David pointed out, we can't hope to capture all function types. We will have to draw the line somewhere. Is it worth the extra complexity to include things like named parameters?

Thanks, this is great data to have for discussion!

More complicated callable types are currently often expressed using callback protocols. For example, I found this one in `stdlib/tkinter/__init__.pyi`:

class _ExceptionReportingCallback(Protocol):
    def __call__(self, __exc: Type[BaseException], __val: BaseException, __tb: TracebackType) -> Any: ...

This could be expressed with Callable but the names provide better documentation.

Similarly, this one is in sharedctypes.pyi:

class _AcquireFunc(Protocol):
    def __call__(self, block: bool = ..., timeout: Optional[float] = ...) -> bool: ...


# Footnotes

Curious: What are some large, typed, open-source Python projects (apart from typeshed) that we can analyze for stats?

The mypy-primer corpus (https://github.com/hauntsaninja/mypy_primer/blob/master/mypy_primer.py#L914) would be a good place to look.

I suspect complicated callable types are more common in application codebases than in reusable libraries (the code you see in typeshed). I haven't tested that assumption though.