classification
Title: Improper use of the keyword-only syntax makes the parser crash
Type: crash Stage:
Components: Interpreter Core Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, amaury.forgeotdarc, christian.heimes
Priority: normal Keywords:

Created on 2007-12-08 18:13 by alexandre.vassalotti, last changed 2008-01-06 22:29 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
kwonly.patch amaury.forgeotdarc, 2007-12-08 22:29
kwonly2.patch amaury.forgeotdarc, 2007-12-08 23:50
Messages (12)
msg58299 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2007-12-08 18:13
I found that the parser fails to handle correctly the (incorrect) case
where the single-star (*), used for delimiting keyword-only arguments,
is immediately followed by a **keywords parameter:

>>> def f(*, **kw):
...   pass
... 
python: Python/ast.c:652: handle_keywordonly_args: Assertion `kwonlyargs
!= ((void *)0)' failed.
[1]    7872 abort (core dumped)  ./python
msg58300 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-08 22:12
Fixed in r59432

I've altered the assert(). It now checks if either kwonlyargs and
kwdefault or both not NULL or the next node is a DOUBLESTAR.
msg58301 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-12-08 22:29
Err... I think it should raise a SyntaxError in this case.
See my attached patch.
msg58302 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-08 22:45
Why do you want to forbid 

def f(*, **kw)

? It's useful and it also works in release builds of Python 3.0a2. It
only breaks in debug builds because the assert() gets triggered.
msg58303 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2007-12-08 22:59
Amaury is right. "def f(*, **kw): pass" should raise a SyntaxError. The
keyword-only delimiter is useless since the **kw parameter already only
accepts keywords.
msg58304 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-12-08 23:01
> Why do you want to forbid
>   def f(*, **kw)

Well, TOOWTDI and the like...
and the first time I saw it, it seemed that any number of parameters is
allowed!
msg58306 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-08 23:10
Ah, you and Amaury are right! But I don't like Amaury's error message:

    SyntaxError: no name for vararg

It doesn't explain what's wrong. How about

    SyntaxError: keyword only arguments require at least one keyword
msg58308 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-08 23:18
Kirk McDonald has an even better error message for us:

SyntaxError: Cannot specify keyword only arguments without named arguments
msg58309 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-08 23:27
Here is another error message from Thomas Wouters 'named arguments must
follow bare *'
msg58310 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-12-08 23:50
Right.
We should also replace the other occurence of "no name for vararg".
Here is another patch, against the current revision (59434).
msg58319 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-09 15:52
I'm fine with your patch. Can you commit it please?
msg58330 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-12-09 21:50
Committed revision 59443.
History
Date User Action Args
2008-01-06 22:29:44adminsetkeywords: - py3k
versions: Python 3.0
2007-12-09 21:50:46amaury.forgeotdarcsetstatus: open -> closed
messages: + msg58330
2007-12-09 15:52:23christian.heimessetmessages: + msg58319
2007-12-08 23:50:53amaury.forgeotdarcsetfiles: + kwonly2.patch
messages: + msg58310
2007-12-08 23:27:25christian.heimessetmessages: + msg58309
2007-12-08 23:18:38christian.heimessetmessages: + msg58308
2007-12-08 23:10:37christian.heimessetmessages: + msg58306
2007-12-08 23:01:45amaury.forgeotdarcsetmessages: + msg58304
2007-12-08 22:59:58alexandre.vassalottisetmessages: + msg58303
2007-12-08 22:45:39christian.heimessetmessages: + msg58302
2007-12-08 22:38:13amaury.forgeotdarcsetstatus: closed -> open
2007-12-08 22:29:25amaury.forgeotdarcsetfiles: + kwonly.patch
nosy: + amaury.forgeotdarc
messages: + msg58301
2007-12-08 22:12:49christian.heimessetstatus: open -> closed
resolution: fixed
2007-12-08 22:12:41christian.heimessetnosy: + christian.heimes
messages: + msg58300
2007-12-08 18:14:13alexandre.vassalottisetversions: + Python 3.0
2007-12-08 18:13:57alexandre.vassalotticreate