<div class="gmail_quote">On Sun, Mar 4, 2012 at 6:16 AM, Ron Adam <span dir="ltr"><<a href="mailto:ron3200@gmail.com">ron3200@gmail.com</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">On Sat, 2012-03-03 at 16:46 -0800, Guido van Rossum wrote:<br>
> On Sat, Mar 3, 2012 at 4:15 PM, Ron Adam <<a href="mailto:ron3200@gmail.com">ron3200@gmail.com</a>> wrote:<br>
> > I just can't think of a good case where I would want to prohibit setting<br>
> > an argument by name on on purpose.  But I suppose if I encountered a<br>
> > certain error that may have been caught by doing so, I may think about<br>
> > doing that. <shrug><br>
><br>
> Apparently you skipped part of the thread. <shrug**2><br>
<br>
</div>Yep, I missed Nicks message where he points out...<br>
<div class="im"><br>
> The other use case is APIs like the dict constructor and dict.update<br>
> which are designed to accept arbitrary keyword arguments, so you don't<br>
> want to reserve particular names in the calling argument namespace for<br>
> your positional arguments.<br>
<br>
<br>
</div>>>> def dct(a, **kwds):<br>
...   return a, kwds<br>
<br>
>>> dct(42, a=2)<br>
<div class="im">Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
</div>TypeError: dct() got multiple values for keyword argument 'a'<br>
<br>
Would the positional decorator fix this particular case?  It seems like<br>
it would work for forcing an error, but not for multiple values with the<br>
same name.<br>
<br>
<br>
The way to currently get around this is to use *args along with **kwds.<br>
<br>
>>> def dct(*args, **kwds):<br>
...     (n,) = args           # errors here if incorrect number of args.<br>
...     return n, kwds<br>
...<br>
>>> dct(3, n=7, args=42, kwds='ok')<br>
(3, {'args': 42, 'kwds': 'ok', 'n': 7})<br>
<br>
The names used with '*' and '**' are already anonymous as far as the foo<br>
signature is concerned, so you can use args or kwds as keywords without<br>
a problem.<br>
<br>
I'm not sure what the positional decorator would gains over this.<br>
<br>
<br>
The other use case mentioned is the one where you point out overriding<br>
an undocumented variable name.  Seems like this is a question of weather<br>
or not it is better to make python behavior match the C builtins<br>
behavior, vs making the C builtins behavior match python behavior.<br>
<br>
<br>
Cheers,<br>
   Ron<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br><div>There are two issues being discussed here:</div><div><br></div><div>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?</div>

<div><br></div><div>2.  How to avoid the problems with name-binding to an intended positional only argument.  Once again, this can be dealt with using *args.</div><div><br></div><div>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:</div>

<div><br></div><div># pos(2) indicates 2 positional arguments</div><div>def f(pos(2), arg1, *args, **kwargs):</div><div>    print(pos)</div><div>    print(arg1)</div><div>    print(args)</div><div>    print(kwargs)</div>
<div>
<br></div><div>>>> f(1, 2, 'other', 'args', pos='arguments')</div><div>(1, 2)</div><div>'other'</div><div>('args',)</div><div>{'pos': 'arguments'}</div><div>

<br></div><div>I'm +0 on the whole idea, but only if it deals with both issues.</div><div><br></div><div>David</div>