On Tue, Apr 21, 2020 at 6:56 PM Alex Hall <alex.moj...@gmail.com> wrote:
>
> Exposing the AST is probably overkill, but we could probably come up with a 
> different way to give Python users easy access to the argument names. For 
> example, suppose you could define functions like this:
>
> ```
> foo = 1
> bar = 2
>
> # Note the ***, different from **
> def Q(***args_with_names):
>     return args_with_names
>
> assert Q(foo, bar) == dict(foo=foo, bar=bar)
> ```
>
> Then you would only need a few small instances of magical syntax. Most users 
> would never need to know what `***` means. If they come across a function 
> call like `func(**Q(foo, bar))`, they can at least tell that keyword 
> arguments are being passed. And the function Q would be easy to google or 
> inspect with help(Q) in the shell. The syntax for calls and dicts wouldn't 
> need to be complicated further.
>

To make this work, Python would either have to provide those names to
every function no matter what (massive overkill and a significant
backwards-compatibility change), or would somehow need to know the
function's calling convention prior to calling it. Normally, the
details of the way parameters are passed is controlled entirely by the
call site - these ones are positional, those are keyword - and then
the function receives them. For this, you'd need to have something
that *looks* positional but *acts* keyword. I think it'd be best to
adorn the call site rather than the function.

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

Reply via email to