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
When using decorators, we often know that the function that will be decorated should take param x and y, but we don't care about the rest of the parameters. Is there currently a way to do this ?
Something like Callable[[str,...], Any] would be perfect. It would work for f(x: str) but also for f(x: str, y: int) and f(x: str, *args, **kwargs)
This is actually very similar to #5876 (see also a decorator example there). Which is opposite to the idea of callback protocols in some sense. Callback protocols allow to express signatures that are impossible to express using Callable syntax. However, there is something that can be expressed using Callable that can't be expressed as a signature, for example Callable[..., int] (with literal ...).
Potentially we can just also allow special meaning for *args: Any, **kwds: Anyat the end of a signature to mean "I don't care" instead of "Should allow all possible calls".
We don't want to support a non-standard extension to the callable syntax, so proposed changes should go through the typing issue tracker or typing-sig@.
Activity
JelleZijlstra commentedon Dec 18, 2018
You can do this with callable protocols (https://mypy.readthedocs.io/en/latest/protocols.html#callback-protocols).
mehdigmira commentedon Dec 18, 2018
I was not able to make it work with callable protocols either
Am I doing smth wrong ?
ilevkivskyi commentedon Dec 18, 2018
This is actually very similar to #5876 (see also a decorator example there). Which is opposite to the idea of callback protocols in some sense. Callback protocols allow to express signatures that are impossible to express using
Callablesyntax. However, there is something that can be expressed usingCallablethat can't be expressed as a signature, for exampleCallable[..., int](with literal...).Potentially we can just also allow special meaning for
*args: Any, **kwds: Anyat the end of a signature to mean "I don't care" instead of "Should allow all possible calls".JukkaL commentedon Jan 29, 2020
We don't want to support a non-standard extension to the callable syntax, so proposed changes should go through the typing issue tracker or typing-sig@.