On Jul 15, 2019, at 05:25, Anders Hovmöller <bo...@killingar.net> wrote: > > >>>> (The fact that they’re positional, but passed as if they were keyword, >>>> accepted as if they were keyword, and then pulled out by iterating **kw in >>>> order is also confusing.) >>> >>> What is positional? >> >> The name-value pairs are positional. If the keyword names aren’t being used >> to match the values to parameter names, or to distinguish the values in any >> other way, but instead to smuggle in arbitrary extra string values, how else >> can you handle them but by position? Consider a concrete example, your >> plot(=lambda x:x*2, =lambda x:x**2). How could plot process that? > > It's a syntax error. Just like normal keyword arguments: > >>>> def f(**kwargs): print(kwargs) > ... >>>> f(a=1, a=2) > File "<string>", line 1 > SyntaxError: keyword argument repeated
Why would two similar but different lambdas (doubling vs. squaring) with similar but different string forms (one * vs two) give a syntax error? I didn’t come up with the plot example, so I don’t know the reason it took two functions. But let’s say they represent functions for the y and z values respectively for each x, or the real and imaginary parts of a function on complex x, or the theta and phi values for each r, or two independent functions f and g that we want to plot the area between, or whatever. So, how does plot know which argument is y and which is a? It can’t be by the names, because the names are stringified lambda expressions. The only thing it can do is treat the first name-value pair in kwargs as y, and the second we z. In other words, it has to treat them as if they were positional arguments. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/IS4BNYEQ5ZYAODWBCT625YSQECFKCSMO/ Code of Conduct: http://python.org/psf/codeofconduct/