[Python-ideas] Short form for keyword arguments and dicts

Anders Hovmöller boxed at killingar.net
Sun Jun 23 15:30:09 CEST 2013


> (which I consider too ugly for words), but it does absolutely nothing for:
>
>
> create_user(first_name=record[**3], last_name=record[2],
> contact_email=record.email)
>
> create_user(first_name=**personal_name, last_name=family_name,
> contact_email=email_address)
>
> create_user(first_name="**Steven", last_name="D'Aprano", contact_email="
> steve at example.**com <steve at example.com>")
>
> create_user(first_name=first_**name.title(), last_name=last_name.title(),
> contact_email=validate_and_**clean(contact_email))
>
> The special case "parameter name matches exactly argument expression" is
> far too special, and the benefit far too minor, to deserve special syntax.
>

I disagree. I think small things can have big impacts because the design of
a system shapes the usage of the system.


> Oh, one last thing... your suggestion is also brittle. If you refactor the
> variable name, or change the function parameter name, code using this
> shortcut will break.


Let's go through that statement. Refactoring variable names: yes, if you
search/replace without checking the diff or using a tool that doesn't
understand the syntax that'd probably screw it up. Which of course is true
whenever you use the wrong tool for the wrong job and you're sloppy about
it. The code will still break by pointing out that there's no such argument
to the function which is better than positional arguments, and if you're
sloppy about it you'd screw up "foo(bar=bar)" when trying to rename "bar".
So that argument is pretty clearly moot.

If you change the function parameter name: then all calls using keyword
arguments will fail with a pretty good error message. This is 100% the same
between python code today and with my shortcut. So again, moot.


> Parameter names are part of the function API and shouldn't change, but
> variable names are not, and should be free to change. With your suggestion,
> they can't.


The transformation to the code when changing variables names will in some
cases be bigger yes. Saying that variable names aren't free to change is
hyperbole though.

As for parameter names being part of an API, well yes, that's true, but
code changes. Just saying that we should never change the parameter names
of any function after it has been called once isn't what you meant right?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130623/3661b327/attachment-0001.html>


More information about the Python-ideas mailing list