Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper use of the keyword-only syntax makes the parser crash #45914

Closed
avassalotti opened this issue Dec 8, 2007 · 12 comments
Closed

Improper use of the keyword-only syntax makes the parser crash #45914

avassalotti opened this issue Dec 8, 2007 · 12 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@avassalotti
Copy link
Member

BPO 1573
Nosy @amauryfa, @tiran, @avassalotti
Files
  • kwonly.patch
  • kwonly2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2007-12-09.21:50:46.338>
    created_at = <Date 2007-12-08.18:13:57.020>
    labels = ['interpreter-core', 'type-crash']
    title = 'Improper use of the keyword-only syntax makes the parser crash'
    updated_at = <Date 2008-01-06.22:29:44.524>
    user = 'https://github.com/avassalotti'

    bugs.python.org fields:

    activity = <Date 2008-01-06.22:29:44.524>
    actor = 'admin'
    assignee = 'none'
    closed = True
    closed_date = <Date 2007-12-09.21:50:46.338>
    closer = 'amaury.forgeotdarc'
    components = ['Interpreter Core']
    creation = <Date 2007-12-08.18:13:57.020>
    creator = 'alexandre.vassalotti'
    dependencies = []
    files = ['8894', '8895']
    hgrepos = []
    issue_num = 1573
    keywords = []
    message_count = 12.0
    messages = ['58299', '58300', '58301', '58302', '58303', '58304', '58306', '58308', '58309', '58310', '58319', '58330']
    nosy_count = 3.0
    nosy_names = ['amaury.forgeotdarc', 'christian.heimes', 'alexandre.vassalotti']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue1573'
    versions = ['Python 3.0']

    @avassalotti
    Copy link
    Member Author

    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

    @avassalotti avassalotti added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Dec 8, 2007
    @tiran
    Copy link
    Member

    tiran commented Dec 8, 2007

    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.

    @tiran tiran closed this as completed Dec 8, 2007
    @amauryfa
    Copy link
    Member

    amauryfa commented Dec 8, 2007

    Err... I think it should raise a SyntaxError in this case.
    See my attached patch.

    @amauryfa amauryfa reopened this Dec 8, 2007
    @tiran
    Copy link
    Member

    tiran commented Dec 8, 2007

    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.

    @avassalotti
    Copy link
    Member Author

    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.

    @amauryfa
    Copy link
    Member

    amauryfa commented Dec 8, 2007

    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!

    @tiran
    Copy link
    Member

    tiran commented Dec 8, 2007

    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
    

    @tiran
    Copy link
    Member

    tiran commented Dec 8, 2007

    Kirk McDonald has an even better error message for us:

    SyntaxError: Cannot specify keyword only arguments without named arguments

    @tiran
    Copy link
    Member

    tiran commented Dec 8, 2007

    Here is another error message from Thomas Wouters 'named arguments must
    follow bare *'

    @amauryfa
    Copy link
    Member

    amauryfa commented Dec 8, 2007

    Right.
    We should also replace the other occurence of "no name for vararg".
    Here is another patch, against the current revision (59434).

    @tiran
    Copy link
    Member

    tiran commented Dec 9, 2007

    I'm fine with your patch. Can you commit it please?

    @amauryfa
    Copy link
    Member

    amauryfa commented Dec 9, 2007

    Committed revision 59443.

    @amauryfa amauryfa closed this as completed Dec 9, 2007
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants