<div class="gmail_quote">On 20 September 2012 16:14, Benjamin Peterson <span dir="ltr"><<a href="mailto:benjamin@python.org" target="_blank">benjamin@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

2012/9/20 Mark Dickinson <<a href="mailto:dickinsm@gmail.com" target="_blank">dickinsm@gmail.com</a>>:<br>
<div>> And excepting optional ones, too, right?  E.g., the c in<br>
><br>
>     def foo(a, b, c=1, *args, d):<br>
>         pass<br>
><br>
> can be passed to by position, but isn't "positional".<br>
<br>
</div>Why not?<br>
<br>
>>> def f(a, b, c=3): pass<br>
<div>...<br>
>>> f()<br>
Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
</div>TypeError: f() missing 2 required positional arguments: 'a' and 'b'<br>
>>> f(1, 2, 3, 4)<br>
<div>Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
</div>TypeError: f() takes from 2 to 3 positional arguments but 4 were given<br></blockquote><div><br></div><div>The difference between c and a,b is that c is optional, whereas a and b are required.</div>
<div><br></div><div>In Python 2.x there are named arguments and variadic arguments. There are two types of named arguments: required and optional. There are also two types of variadic arguments: positional and keyword. i.e.:</div>

<div><br></div><div>named</div><div>  required</div><div>  not-required</div><div>variadic</div><div>  positional</div><div>  keyword</div><div><br></div><div>In Python 2.x all named parameters can be passed by position or by keyword, so it doesn't make sense to use those concepts to distinguish them. On the other hand, for variadic parameters that distinction is crucial.</div>

<div><br></div><div>In Python 3.x there are two orthogonal properties for each named parameter. The parameter can be required or optional as before, and then the parameter can be keyword-only or positional. There are 4 combinations of these two properties:</div>
<div><br></div><div>def f(a, b=1, *, c, d=3): pass</div><div><br></div><div>                   | required | optional</div><div>positional | a              | b</div><div>kwonly       | c              | d</div><div><br></div>
<div>Since there are two orthogonal properties of a parameter (requiredness and positionness) it makes perfect sense to use two adjectives to describe each parameter as is the case for the error message shown at the start of this thread:</div>
<div><br></div><div>Mark Dickinson wrote:</div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">>>>> def f(x): pass</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">>...</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">>>>> f()</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">>Traceback (most recent call last):</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">>  File "<stdin>", line 1, in <module></span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">>TypeError: f() missing 1 required positional argument: 'x'</span>
</div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13.333333969116211px;background-color:rgb(255,255,255)">I would say that the only problem with this terminology is that it would be good to think of a word to replace "keyword-only" (positionless?).</span></div>
<div><br></div><div>Oscar</div></div>