[Python-3000] Is this really a SyntaxError?

Amaury Forgeot d'Arc amauryfa at gmail.com
Wed Jul 30 11:34:41 CEST 2008


Guido van Rossum wrote:
> On Tue, Jul 29, 2008 at 3:51 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> Georg Brandl wrote:
>>>
>>> Georg Brandl schrieb:
>>>>
>>>> Someone just wrote to the docs mailing list and reported that the
>>>> itertools
>>>> documentation for Py3k contains this recipe:
>>>>
>>>> def grouper(n, iterable, fillvalue=None):
>>>>     args = [iter(iterable)] * n
>>>>     return zip_longest(*args, fillvalue=fillvalue)
>>>>
>>>> It is currently a syntax error in 3k. There's also a test for it in
>>>> test_keywordonlyarg.py, however, I can currently see no reason why
>>>> it should be disallowed.
>>>
>>> No opinions at all?
>>
>> I think I was busy first time it went by :)
>>
>> With keyword-only parameters allowed now, I think it makes sense to be able
>> to supply the keywords arguments after the variable length argument as well.
>
> Agreed. I doubt that this will be a simple enough change to allow it
> in 3.0 though.

I hope this patch is simple enough for you:

Index: Grammar/Grammar
===================================================================
--- Grammar/Grammar     (revision 65298)
+++ Grammar/Grammar     (working copy)
@@ -113,7 +113,9 @@

 classdef: 'class' NAME ['(' [arglist] ')'] ':' suite

-arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test)
+arglist: (argument ',')* (argument [',']
+                         |'*' test (',' NAME '=' test)* [',' '**' test]
+                         |'**' test)
 argument: test [comp_for] | test '=' test  # Really [keyword '='] test

 comp_iter: comp_for | comp_if


(and call pgen to rebuild the graminit.c)

Positional arguments after the *args are explicitly disallowed:
        f(1, *[2, 3], 4, z=5)
The syntax could make sense, but this would require more changes in
the compiler,
to properly order the parameters.

-- 
Amaury Forgeot d'Arc


More information about the Python-3000 mailing list