Repository navigation
Description
Originally submitted to Google Code by @pekkaklarck on 1 Nov 2013
Python keywords have supported kwargs since RF 2.8 (#1383) and dynamic libraries ought to get the support in RF 2.8.2 (#1500). Full powers of this handy new functionality cannot be used yet, though, because user keywords cannot take kwargs. This limitation is illustrated by the examples below.
First, let's assume we a keyword like below for running a some program:
*** Keywords ***
Run My Program
[Arguments] @{args}
Run Process myprog @{args} stdout=/tmp/stdout.txtThe above keyword uses Process.Run Process keyword, which takes optional configuration parameters as kwargs. Using the keyword is simple:
*** Test Cases ***
Example
Run My Program # no argument
Run My Program arg1 arg2 # two argumentsThe problem is that we cannot change the keyword to take optional configuration. The best we can do is this:
*** Keywords ***
Run My Program
[Arguments] ${stdout}=/tmp/stdout.txt @{args}
Run Process myprog @{args} stdout=${stdout}Unfortunately, running it like earlier won't work anymore:
*** Test Cases ***
Example
Run My Program # this still works
Run My Program arg1 arg2 # ooops, ${stdout} got value arg1!!
Run My Program out.txt arg # works but is hard to understandA solution to this problem is enhancing user keywords so that they can take free kwargs just like Python (and soon dynamic) keywords can. In practice the keyword could look something like this:
*** Keywords ***
Run My Program
[Arguments] @{args} &{config}
Run Process myprog @{args} &{config}and could be used like
*** Test Cases ***
Example
Run My Program arg1 arg2 # same as original
Run My Program arg stdout=out.txt # works and is clearAs the above example shows, a key to resolving this issue is having a new variable type that gets free keyword arguments and can be used to pass them further. It will naturally be a dictionary, and can be also used for other purposes (#1450). Will the new variable use &{name} syntax or something else is still open.
Changes needed to implement this issue are so large that it can only be done in a major release.
Activity
guykisel commentedon Aug 1, 2014
Suggestion: Since RF uses
@{args}for the equivalent of Python*args, could RF use@@{args}for the equivalent of Python**kwargs?pekkaklarck commentedon Aug 1, 2014
It will likely be easier to implement this if we just use a single character specifier. Anyway, deciding about that part if issue #1450.
Support &{dict} variables in variable table
Using &{dict} variables with keyword.
Added &{kwargs} support to user keywords (#1561)
Trace logging &{kwargs} still missing from #1561
pekkaklarck commentedon Feb 8, 2015
Trace logging &{kwargs} was implemented by 681c65e. This issue now waits for
dict-variablebranch to be merged to master and documentation in User Guide.[-]Support Python style `**kwargs` with user keywords[/-][+]Support Python style `**kwargs` with user keywords using `&{kwargs}` syntax[/+]Test that user keyword &{kwargs} (#1561) work correctly with Libdoc