Skip to content

Python's keyword argument syntax is supported #1383

Closed

Description

@spooning

Originally submitted to Google Code by @pekkaklarck on 14 Mar 2013

Python has so called keyword argument syntax which allows defining functions like

def func(**kwargs):
    pass

and then calling them like

func(foo=1, bar='two')

In this example the value of kwargs inside func would be a dictionary {'foo': 1, 'bar': 'two'}.

Supporting this syntax with Python based test libraries would sometimes be handy. For example, this would make it easier to add optional configuration parameters to keywords in the new Process library ( issue 485 ). We would like to create keyword like this

def run_process(command, *args, **conf):
    # ...

and call it like

Run Process    ls    -h    cwd=/tmp

The idea would be that conf in the above example would contain {'cwd': '/tmp'}.

Most likely this could be implemented so that if a function implementing a keyword has keyword arguments, all arguments at the end of the keyword call in format name=value would be put into it.

If there are also default values, populating them has preferences:

def example(foo='bar', **kwargs):
    pass

Example    foo=zap    kw=arg    second=kw_arg

In the above example foo would get value zap and kwargs would be {'kw': 'arg', 'second': 'kw_arg'}.

Activity

  1. added this to the 2.8 milestone on Jun 29, 2014
  2. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 2 Apr 2013

    Other changes in revision 61867ad0783f and revision f8f75df26942.

  3. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 10 May 2013

    Documentation is covered by issue 1430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions