Hi All, I'm transferring a response over from https://github.com/python/peps/pull/1259 to a comment from Sebastian Kreft to keep our discussion consolidated.
I do have some questions regarding the proposed PEP. Those questions were being written while the PR was merged.
1) I'm missing a brief description on what happens to keyword only (PEP 3102 https://www.python.org/dev/peps/pep-3102/) and to positional only (PEP 570 https://www.python.org/dev/peps/pep-0570/) arguments.
Will for example the following be accepted or rejected:
def add_logging(f: Callable[Ps, R]) -> Callable[Ps, R]: async def inner(*args: Ps.args, **kwargs: Ps.kwargs) -> R: # log return f(*args, **kwargs) return inner
@add_logging def add(x:int, *, y: int = 0): return x + y
add(1, 2)
Note that today in Mypy, that add call (without the decorator) will be rejected.
I only found there's some talk abut it in the rejected proposals section.
Yes the decorated version will still be correctly rejected under the new proposal. This will be because the entire specification of the parameter of the decorated function will be transferred over, including the keyword-only-ness of `y`. Where do you see a mention of this in the rejected alternatives section? I'd like to clarify that confusion there if possible.
2) What do you mean by anonymous arguments? Are those arguments prefixed by double underscore (__) as in the provided example. Is that rule enforced or suggested?
These are defined in PEP484 (https://www.python.org/dev/peps/pep-0484/#positional-only-arguments), and are enforced by type checkers, not the runtime
3) What is the motivation to require TParams.args and TParams.kwargs to be used together.
Why is the example def baz(*args: TParams.args) -> int rejected?
The reason is that only by using them together do they come together into a callable type that can be actually called. Consider ``` def partial_decorator(f: Callable[TParams, int]) -> ???: def inner(*args: TParams.args) -> int: return f(*args) # This is an unsafe call return inner # What is the type of inner? ``` If you only want access to the positional parameters of a function, you can use a ListVariadic (currently in pyre_extensions, to be standardized in a forthcoming PEP), like so: ``` from typing import Callable, TypeVar from pyre_extensions.type_variable_operators import Concatenate Ts = pyre_extensions.ListVariadic("Ts") def prepend_addition_argument(f: Callable[[Ts], int]) -> Callable[[Concatenate[int, Ts]], str]: def inner(x: int, *args: Ts) -> str: return str(x + f( *args)) return inner @prepend_addition_argument def foo(x: int, y: int) -> int: return x + y reveal_type(foo) # typing.Callable(foo)[[int, int, int], str] ```