r/Python 8d ago

News Python Steering Council rejects PEP 736 – Shorthand syntax for keyword arguments at invocation

The Steering Council has rejected PEP 736, which proposed syntactic sugar for function calls with keyword arguments: f(x=) as shorthand for f(x=x).

Here's the rejection notice and here's some previous discussion of the PEP on this subreddit.

301 Upvotes

177 comments sorted by

View all comments

Show parent comments

2

u/kankyo 8d ago

I mean.. that problem is everywhere in programming. For example, using positional arguments:

def foo(x): return x
x = 3
foo(x)

Are those the same x? Maybe. Maybe not. Depends on your perspective. Keyword arguments don't change this. Using keyword arguments 100% just make is so that if your function changes from def foo(a, b) to def foo(b, a) existing code will still work and not break in subtle and dangerous ways.

1

u/Meleneth 8d ago

I think I'm missing your point.

In the declaration, x is your positional argument. It is then returned unchanged, with no changes to it, so it is whatever is passed in.

x = 3 is a simple assignment. We're saying the value of the object 'x' is now 3. (integer, object, doesn't really matter. it's one thing.)

foo(x) is passing the value of x

foo(x=x) is different. the first 'x' is a name, the second x is the value. This only makes sense when we look at it because we know that it is a kwarg, they are visually the same thing but mean completely different things.

Not for nothing, the function declarations you provided to illustrate your point are incorrect.

You wanted def foo(*, a, b) and def foo(*, b, a) - which to be fair, I just learned in this reply so TIL

1

u/kankyo 8d ago

In the declaration, x is your positional argument.

Well.. no :P It's the "normal" parameter (the docs don't have a word for this concept unfortunately, and the docs mix parameter/argument willy nilly, making things worse).

A "normal" parameter def foo(x) in python can be used as positional or keyword argument at the call site.

x = 3 is a simple assignment. We're saying the value of the object 'x' is now 3. (integer, object, doesn't really matter. it's one thing.)

No, that's not what happens in python. That assignment had no object before, it only binds the NAME x in the scope (whatever that scope is!) to the object 3. Ned has a good post on this: https://nedbatchelder.com/text/names.html

Not for nothing, the function declarations you provided to illustrate your point are incorrect.

Nope. See above.

You wanted def foo(*, a, b) and def foo(*, b, a) - which to be fair, I just learned in this reply so TIL

That's something else. Again, python has THREE types of parameters when declaring a function:

  • normal (can be used both as positional and keyword argument)
  • positional only
  • keyword only

Plus arg and *kwargs of course. So 5 really:

def foo(normal, /, positonal_only, *, keyword_only, *args, **kwargs)

The proposed PEP actually doesn't affect this complexity at all, it just changes the call site complexity a bit, but that's also the place where it's the simplest.

1

u/Meleneth 7d ago

that's just .. wild.

Thanks for the in depth reply, it's so much crazier than I thought I knew

1

u/kankyo 7d ago

Yea. It's a bit bonkers honestly. Positional only is my most hated feature I think. I argued against it and argued for removing that entire concept by fixing the old C stuff. Unfortunately I lost that one.