On Fri, Apr 17, 2020 at 3:03 AM <oliveira.rodrig...@gmail.com> wrote:
>
> (Steven D'Aprano)
> >  Do any other languages already have this feature?
>
> JavaScript ES6 has similar feature:
>
> ```javascript
> x = 1
> y = 2
> do_something({ x, y })
> ```

Very few other languages even *have* keyword arguments, so the nearest
you'll get is something like this, where it's actually being wrapped
up into a dict-like object.

Here are a few examples gleaned by skimming a single file in one of my projects:

r = requests.request(method, "https://api.twitch.tv/"; + endpoint,
    params=params, data=data, headers={
    "Accept": "application/vnd.twitchtv.v5+json",
    "Client-ID": config.CLIENT_ID,
    "Authorization": auth,
})

# Recursion (the token mess is scheduled for change anyway):
return query(endpoint, token="bearer" if token == "bearer" else "oauth",
    method=method, params=params, data=data, auto_refresh=False)

# This pattern is VERY common. After doing the work, we pass a
# whole bunch of info to the template renderer.
return render_template("index.html",
    twitter=twitter, username=user["display_name"],
    channel=channel, channelid=channelid, error=error,
    setups=database.list_setups(channelid),
    sched_tz=sched_tz, schedule=schedule, sched_tweet=sched_tweet,
    checklist=database.get_checklist(channelid),
    timers=database.list_timers(channelid),
    tweets=tweets,
)

# There are also cases where I *could* use kwargs, but I don't,
# because it would be clunkier in syntax. This mixes positional
# and keyword just so that I don't need channelid=channelid.
database.update_timer_details(channelid, id,
    title=request.form["title"],
    delta=parse_time(request.form["delta"]),
    maxtime=parse_time(request.form["maxtime"]),
    styling=request.form.get("styling", ""),
)


So yes, this definitely does happen in the real world. I think it
would be nice to have a shorthand syntax, but it's not a killer
feature. I'm +0.75 on adding this.

ChrisA
_______________________________________________
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/XCTHR5C3546FGFFH3I3F4GZ6N76CZFMD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to