Status: Accepted
Owner: ----
Labels: Type-Enhancement Priority-High Target-2.9
New issue 1561 by pekka.klarck: Support Python style `**kwargs` with user
keywords
http://code.google.com/p/robotframework/issues/detail?id=1561
Python keywords have supported kwargs since RF 2.8 (issue 1383) and dynamic
libraries ought to get the support in RF 2.8.2 (issue 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.txt
The above keyword uses `Process.Run Process` keyword, which takes optional
configuration parameters as kwargs. Using the keyword is simple:
Run My Program # no argument
Run My Program arg1 arg2 # two arguments
The 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:
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 understand
A 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
Run My Program arg1 arg2 # same as original
Run My Program arg stdout=out.txt # works and is clear
As 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 (issue 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.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
---
You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.