<br><br><div class="gmail_quote">On Sun, Mar 4, 2012 at 5:34 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">David Townshend wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
There are two issues being discussed here:<br>
<br>
1.  A new syntax for positional-only arguments.  I don't really see any good use case for this which can't already be dealt with quite easily using *args.  True, it means a bit more work on the documentation, but is it really worth adding new syntax (or even a built-in decorator) just for that?<br>


</blockquote>
<br></div>
The problem with *args is that it allows 0-N arguments, when we want, say, 2.<div class="im"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2.  How to avoid the problems with name-binding to an intended positional only argument.  Once again, this can be dealt with using *args.<br>
</blockquote>
<br></div>
Again, the problem is *args accepts a range of possible arguments.<div class="im"><br></div></blockquote><div><br>
Agreed, but why not this?<br>
<br>
def f(*args, **kwargs):<br>
    assert len(args) == 2<br>
<br>
The exception raised could easily be a TypeError too, so it would 
appear, to a user, the same as defining it in the function signature.  
There are of course, other limitations (e.g. introspection), but without
 a specific use case it is difficult to know how important those 
limitations are.<br> 
<br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In both cases it would be nice to be able to avoid having to manually parse *args and **kwargs, but I haven't really seen anything better that the status quo for dealing with them. The only way I see this really working is to somehow bind positional-only arguments without binding each them to a specific name, and the only way I can think of to do that is to store them in a tuple.  Perhaps, then, the syntax should reflect a C-style array:<br>


<br>
# pos(2) indicates 2 positional arguments<br>
def f(pos(2), arg1, *args, **kwargs):<br>
    print(pos)<br>
    print(arg1)<br>
    print(args)<br>
    print(kwargs)<br>
</blockquote>
<br></div>
Not good.  The issue is not restricting the author from binding the positional arguments to names, the issue is restricting the user from binding the arguments to names -- but even then, the user (and the author!) need to have those names apparent.<br>

</blockquote><div><br>Why does the user need the names?  If the user cannot use them as keywords, then it doesn't matter what the names are, so anything can be used in the documentation (which is the only place they would appear).  The author doesn't need the names either, just the data they refer to, in this case a tuple.<br>

 <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
For example:<br>
<br>
  str.split(pos(2))<br>
<br>
Quick, what should be supplied for the two positional arguments?<br></blockquote><div><br>Is that a function call or definition?  My suggestion was to use the parenthesis in the definition, not the call.  Since str.split only has optional arguments its not a good example, but if you were to redefine str.replace (in python) it would look like this:<br>

<br>def replace(pos(3), count=None):<br>    self, old, new = pos<br>    ...<br><br>It would still be called in the same way though:<br><br>>>> 'some string'.replace('s', 't', 1)<br>'tome string'<br>

<br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
We want the arguments bound to names *in the function* -- we don't want the arguments bound to names *in the function call*.<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br>That is what I proposed, I just suggested binding all of the positinoal-only arguments to a single name.<br>

<br>Having given it a bit more thought, though, maybe it would be easier to optionally apply the parenthesis to *args:<br><br>def replace(self, *args(2), count=None);<br>   old, new = args<br><br>This looks much closer to current situation, and I suppose could be extended to **kwargs, limiting the number of keyword arguments (although I have no idea why this would ever be wanted!) <br>

</div></div>