On Fri, 17 Apr 2020 at 17:06, David Mertz <mertz@gnosis.cx> wrote:
I'm kinda leaning -0.5 even on the form that I think is least bad (the mode switch approach).

If typing the same variable from the caller to use in the parameter is really too much repetition, you could maybe just do this:


For what matters, when I stopped to think about this, I came out with this exactly
design!

Maybe this is a 'one obvious way' to deal with it, without changing any
syntax?

 
>>> render_template("index.html",
...     username="display_name",
...     setups="setups",
...     **Q("x y z"))
('index.html',)

{'username': 'display_name', 'setups': 'setups', 'x': 1, 'y': 2, 'z': 3}

Perhaps the spelling of `Q` might be something else.  But in terms of character count, it's not worse than other proposals.

And luckily all you need to do this is get a version of Python later than 1.4 or something like that. :-)

>>> def Q(names):
...     import sys
...     caller = sys._getframe(1)
...     dct = {}
...     for name in names.split():
...         dct[name] = eval(name, globals(), caller.f_locals)
...     return dct


On Fri, Apr 17, 2020 at 2:41 PM Paul Svensson <paul-python@svensson.org> wrote:
For what it's worth, I'm a strong -1 on this whole thing, regardless of syntax.
I think passing a lot of same-named parameters is an anti-pattern, that should be discouraged, not made easier.
Passing an occasional x=x to so some function no disaster;
if it happens often enough to be a problem, IMNSHO, you should look to change your coding style, not the language.

--
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
To unsubscribe send an email to python-ideas-leave@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/IXARPTMYDHA77JUTPJVPJKK3RJYTHQAK/
Code of Conduct: http://python.org/psf/codeofconduct/