4 ms·
PEP 736 – Shorthand syntax for keyword arguments at invocation
- belval 3y agoFrankly I'm a bit torn on this one as f(x=x) is indeed a common pattern and having just f(x=) reduces the need for multiline invocations but I feel like adding syntatic sugar to python at this point is just giving the snake diabetes.
- stefanos82 3y ago> ...but I feel like adding syntactic sugar to python at this point is just giving the snake diabetes. Haha! :D nice one! Personally I would prefer if they chose the `f(:x)` syntax, because it reminds me of how Ruby uses symbols to represent instance variables.
- SushiHippie 3y agoThey mention this on in "Prior Art" https://peps.python.org/pep-0736/#prior-art https://peps.python.org/pep-0736/#prior-art And it just makes sense to do it this way as a) it is basically the same as in ruby, except that the long form in ruby uses a colon and python uses an equals sign b) this syntax already exists in python for f-strings But I agree x= looks a bit "unfinished" and erroneous while :x does not IMO, though I'm looking forward to do fewer keypresses if this gets released.
- HackerThemAll 3y agomy_function(my_first_variable=, my_second_variable=, my_third_variable=) The coder's laziness have gone too far. That's ridiculous. Just checked, the author is a Google folk, that says a lot.
- flykespice 3y agoI believe it's because Google is more saturated of devs than it actually needs for their current projects, so the surplus is trying to keep their credit afloat by brute forcing useless pitch to outside projects.
- cqqxo4zV46cp 3y agoThe PEP is sponsored by Guido, and it’s something that has been suggested quite a number of times over the years. I’d suggest reading the PEP before commenting about it online.
- cqqxo4zV46cp 3y agoWhat!? Sorry, you’re a software developer, you’re literally in the business of automation. This sort of “back in my day we walked to snow up hill both ways with a sheep on our back”-ism is just absurd.
- zarzavat 3y agoFinally! This makes constructing dicts so much easier. I somewhat dislike the syntax though, =foo would have been better because it stands out more. I feel like syntax should be chosen with eyes and not brain, they may have all kinds of rationales for why foo= is better but it's just going to get lost more easily.
- mborch 3y agoSince any argument after one or more "**" must be a keyword-argument, perhaps f(pos_a, pos_b, **kwargs, kw_a, kw_b, ...) or even f(pos_a, pos_b, **, kw_a, kw_b, ...). This would make the proposal's first example read: my_function(**, my_first_variable, my_second_variable, my_third_variable) More readable IMHO. They do mention f(a, b, *, x) in the proposal and present some objections, but arguably ** makes it easy to understand that these are keyword arguments.