O = TypeVar('O')
def decorator(method : Callable[[O, VarArg(), KwArg()], Any]) -> Callable[[VarArg(), O, KwArg()], Any]:
def x(*args, **kwargs):
return method(args[-1], *args[0:-1], **kwargs)
return x
Required positional args may not appear after default, named or var args
VarArg() or ... to represent the positional args before O
This is a known limitation, we have an existing proposal, but syntax that you propose here was not considered I think. This is relatively low priority on our roadmap, so labelling accordingly (unless it is very easy to implement as a temporary workaround).
I think it should be first decided what syntax and behaviour are expected then someone could more easily pickup and implement it
See https://github.com/python/typing/issues/239 and https://github.com/python/typing/issues/264 for previous discussion.
I've stumbled upon them but couldn't find what was settled. Was there an agreed syntax?
This is the problem :-) There is still not 100% on the preferred syntax.
I'm leaning towards the ... syntax. It's clear, more expressive and more correct than VarArg(). Using asterisk is expressive as well but suggesting a different idea.