On Sat, Sep 8, 2018 at 9:34 AM Anders Hovmöller <bo...@killingar.net> wrote:
> function(a=my_a, c=my_c, *, b, d) > function(*, b, c, d, a=my_a, c=my_c) > Yes, those look less bad. They are also almost certainly should get this message rather than working: TypeError: function() got multiple values for keyword argument 'c' But they also force changing the order of keyword arguments in the call. That doesn't do anything to the *behavior* of the call, but it often affects readability. For functions with lots of keyword arguments there is often a certain convention about the order they are passed in that readers expect to see. Those examples of opening and reading files that several people have given are good examples of this. I.e. most optional arguments are not used, but when they are used they have certain relationships among them that lead readers to expect them in a certain order. Here's a counter-proposal that does not require any new syntax. Is there ANYTHING your new syntax would really get you that this solution does not accomplish?! (other than save 4 characters; fewer if you came of with a one character name for the helper) >>> def function(a=11, b=22, c=33, d=44): ... print(a, b, c, d) ... >>> a, b, c = 1, 2, 3 >>> function(a=77, **use('b d')) 77 2 33 None We could implement this helper function like this: >>> def use(names): ... kws = {} ... for name in names.split(): ... try: ... val = eval(name) ... except: ... val = None ... kws[name] = val ... return kws -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/