LWN: Comments on "Positional-only parameters for Python" https://lwn.net/Articles/785245/ This is a special feed containing comments posted to the individual LWN article titled "Positional-only parameters for Python". en-us Mon, 03 Nov 2025 13:25:10 +0000 Mon, 03 Nov 2025 13:25:10 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Positional-only parameters for Python https://lwn.net/Articles/786322/ https://lwn.net/Articles/786322/ tildeswinton <div class="FormattedComment"> This seems to be a proliferation of the current PEP trend of adding complex functionality for edge cases. I would almost argue that many of these newer PEPs are the Python equivalent of giving a TEDx talk or presenting at another well known conference: there seems to be a stronger desire to have it as a bullet point on their resume than a desire to leave a meaningful, lasting impact.<br> </div> Fri, 19 Apr 2019 19:32:35 +0000 Positional-only parameters for Python https://lwn.net/Articles/785874/ https://lwn.net/Articles/785874/ dbaker <div class="FormattedComment"> Which is just so weird to me :)<br> </div> Fri, 12 Apr 2019 20:41:25 +0000 Positional-only parameters for Python https://lwn.net/Articles/785612/ https://lwn.net/Articles/785612/ mgedmin <div class="FormattedComment"> And for extra fun, _ has a special meaning in the REPL (it contains the value of the last expression).<br> <p> $ python3<br> Python 3.6.7 (default, Oct 22 2018, 11:32:17) <br> [GCC 8.2.0] on linux<br> Type "help", "copyright", "credits" or "license" for more information.<br> <font class="QuotedText">&gt;&gt;&gt; 2 + 2</font><br> 4<br> <font class="QuotedText">&gt;&gt;&gt; print("hi")</font><br> hi<br> <font class="QuotedText">&gt;&gt;&gt; _</font><br> 4<br> <p> </div> Thu, 11 Apr 2019 09:39:52 +0000 Positional-only parameters for Python https://lwn.net/Articles/785563/ https://lwn.net/Articles/785563/ k8to <div class="FormattedComment"> It seems valuable to have a choice on whether to expose the names or not. However, there are many modules where the docs don't talk about the argument names, but keyword arguments make the consuming code vastly more readable.<br> <p> I think the fact that the arg names are exposed by default is essentially a good accident that forces interfaces to be a bit more usable than they are by default.<br> <p> Amusingly I went to a good deal of trouble in some code I made to make the args keyword-only without making the implementation of the callsites harder to read. I had explicit documentation of how calls were required to be made, but used inspection to enforce it. I could used def func(**kwargs) but manually coding all the dispatch would have been really unfortunate.<br> </div> Thu, 11 Apr 2019 02:11:58 +0000 Positional-only parameters for Python https://lwn.net/Articles/785543/ https://lwn.net/Articles/785543/ quotemstr <div class="FormattedComment"> One problem is API signature ambiguity. Say I have a def foo(bar): return bar +1. People right now are allowed to call foo as foo(5) or foo(bar=5). Now suppose I want to refactor foo as "def foo(qux):return 1+qux". Is the change of the argument name a breaking API change? Only if w allow keyword argument specification for bar! Right now, we have to treat argument names as part of a function's signature, and I think that's too constricting.<br> </div> Wed, 10 Apr 2019 22:08:43 +0000 Positional-only parameters for Python https://lwn.net/Articles/785531/ https://lwn.net/Articles/785531/ yootis <div class="FormattedComment"> <p> Why is it ever actually necessary to prevent the use of keyword arguments? The article mentions "what if the API changes", but to me that's all the more reason to use keyword arguments. At least you'd detect the problem. Forcing positional arguments sounds dangerous to me.<br> <p> </div> Wed, 10 Apr 2019 20:52:07 +0000 Positional-only parameters for Python https://lwn.net/Articles/785494/ https://lwn.net/Articles/785494/ juliank <div class="FormattedComment"> Using _ for things to ignore is fine until you want to introduce gettext as _ :D<br> </div> Wed, 10 Apr 2019 17:57:28 +0000 Positional-only parameters for Python https://lwn.net/Articles/785482/ https://lwn.net/Articles/785482/ dbaker <div class="FormattedComment"> not only that, _ is the conventional name of any variables that you're going to ignore. Which is really handy for a lot of things;<br> <p> iterating over containers of containers:<br> <p> for a, b, _ in [(1, 'a', []), (2, 'b', [])]: ...<br> <p> for functions that need to fulfill an interface:<br> <p> def f1(f: str, *, opt: bool = False):<br> def f2(f: str, **_):<br> <p> myval = [f(myval, opt=True) for f in [f1, f2]]<br> <p> with the python3 partial container explosion syntax:<br> <p> a, b, *_ = (1, 2, 3, 4)<br> <p> and a bunch of other cases.<br> </div> Wed, 10 Apr 2019 16:35:32 +0000 Positional-only parameters for Python https://lwn.net/Articles/785441/ https://lwn.net/Articles/785441/ FLHerne <div class="FormattedComment"> That's already valid syntax - `_` is an acceptable name in Python, so it's identical to `def fun(name, *args)`.<br> <p> <font class="QuotedText">&gt;&gt;&gt; def fun(name, *_):</font><br> <font class="QuotedText">&gt;&gt;&gt; print(_)</font><br> ...<br> <font class="QuotedText">&gt;&gt;&gt; fun("A", "B", "C")</font><br> ('B', 'C')<br> </div> Wed, 10 Apr 2019 13:16:59 +0000 Positional-only parameters for Python https://lwn.net/Articles/785427/ https://lwn.net/Articles/785427/ LtWorf <div class="FormattedComment"> Breaking changes in languages are bad.<br> </div> Wed, 10 Apr 2019 11:02:25 +0000 Positional-only parameters for Python https://lwn.net/Articles/785426/ https://lwn.net/Articles/785426/ rgb <div class="FormattedComment"> How about<br> <p> def fun(name, *_):<br> ...<br> <p> </div> Wed, 10 Apr 2019 10:59:38 +0000 Positional-only parameters for Python https://lwn.net/Articles/785417/ https://lwn.net/Articles/785417/ foom <div class="FormattedComment"> But that's exactly the problem: There's no such thing as a "positional argument" to a function defined as Python (vs C) until the new PEP.<br> <p> Maybe you meant that all _required_ arguments should have been made positional only? But, then what about optional arguments? Those must allow keyword calls?<br> </div> Wed, 10 Apr 2019 06:38:52 +0000 Positional-only parameters for Python https://lwn.net/Articles/785416/ https://lwn.net/Articles/785416/ niner <div class="FormattedComment"> Seems to me like the real solution would be to just not allow passing positional arguments by keyword, i.e. keeping them completely separate. That would get rid of the renaming issue, the subclassing issue, the "fmt" issue and all inconsistencies. It would also adhere more to the Python design principles, most of all to:<br> Special cases aren't special enough to break the rules.<br> In the face of ambiguity, refuse the temptation to guess.<br> There should be one-- and preferably only one --obvious way to do it.<br> If the implementation is hard to explain, it's a bad idea.<br> <p> Of course such a change would be quite backwards incompatible. If only they had used the one chance they got to make such changes for actually fixing the language...<br> </div> Wed, 10 Apr 2019 06:14:01 +0000