Just browse through PEP 3102 , it also seems to have something to do with it .
To summarize, patches and options should accept variable arguments, but later you need to accept keyword arguments. Keyword arguments are passed as a dictionary, where variable positional arguments will be wrapped as tuples .
From your example
def import_(ui, repo, patch1=None, *patches, **opts):
Any positional parameters after u1,repo and patch1 will be wrapped as tuples in the patches. Any keyword arguments following variable positional arguments will be placed as Dictionary objects through selections.
Another important thing is that the burden is on the caller to ensure that the non-keyword arg after keyword arg condition is not violated.
So, something that violates this will result in a syntax error.
for example
Called as
import_(1,2,3,test="test") import_(1,2,3,4,test="test") import_(1,2,3,4,5) import_(1,2,patch1=3,test="test")
but
import_(1,2,3,patch1=4,5)
will result in a SyntaxError: non-keyword arg after keyword arg syntax error SyntaxError: non-keyword arg after keyword arg
In the first valid case, import_(1,2,3,test="test")
u1 = 1, repo = 2, patch1 = 3, patches = () and opts={"test":"test"}
In the second valid case, import_(1,2,3,patch1=4,test="test")
u1 = 1, repo = 2, patch1 = 3 , patches = (4) and opts={"test":"test"}
In the third valid case, import_(1,2,3,4,5)
u1 = 1, repo = 2, patch1 = 3 , patches=(4,5), and opts={}
In the fourth valid case, import_(1,2,patch1=3,test="test")
u1 = 1, repo = 2, patch1 = 3 , patches=(), and opts={"test":"test"} you can use patch1 as a keywords argument but doing so you cannot wrap any variable positional arguments within patches