You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support literal list/dict syntax when using @{list} and &{dict} as embedded arguments #2699
Currently you can pass lists and dictionaries as arguments to embedded keywords but there is no way to ensure an argument will be a list or dictionary.
If you pass a list variable into the keyword (test @{list} keyword) it works fine, but it would be nice to be able to embed lists like test firstarg secondarg thirdarg keyword.
To do this you could allow someone writing a decorator for a custom keyword to specify if a variable is a list or a dictionary like @keyword(test @{list} keyword) or @keyword(test &{dict} keyword) instead of only scalars @keyword(test ${var} keyword)
If you'd have a keyword with name test @{list} keyword and it would be used like test firstarg secondarg thirdarg keyword, how could Robot know how to split argument firstarg secondarg thirdarg into a list? Just using a space as a separator wouldn't work too well if the keyword would then also be used like test first arg second arg third arg keyword.
Sorry, I've been trying to find out more about how Robot parses embedded arguments but I'm not that familiar with it yet. But in the case of just one list being embedded into a keyword couldn't you just use a regex to separate the keyword from the list?
This isn't a technical problem. The problem is deciding about the list or dictionary syntax. You proposed that arguments specified as a string firstarg secondarg thirdarg are parsed to a list ["firstarg", "secondarg", "thirdarg"], but then first arg second arg third arg is parsed to ["first", "arg", "second", "arg", "third", "arg"] which clearly is wrong.
Yeah, using single space as a separator would mean that values cannot have spaces. I think we could make this work by requiring all items to be quoted and items to be separate with a comma like in test "first art", "second arg", "third arg" keyword. There would still be a lot of details to decide like do we support both double and single quotes, and should we mandate the variable be surrounded with same quotes in keyword name like test "@{list}" keyword. Handling dictionaries should have it's own syntax too.
Supporting @{list} and &{dict} with embedded arguments could provide a workaround for the problem initially reported as #1595, and lately again as #2705, when using lists or dictionaries. This would require us to support exact Python syntax like test ["first art", "second arg", "third arg"] keyword. That's not too nice format if you'd like to pass a list as an argument otherwise, but we could support other formats as well. I'll add this to RF 3.0.3 scope and see how hard this would be to implement.
RF 3.0.3 has been delayed a lot. Now we want it out ASAP and decided to only include bug fixes in it. I'll thus descope this enhancement to RF 3.1 which we plant to start developing right after RF 3.0.3 is out.
I'm starting to question is this such a great idea in the end. Basically using @{list} and &{dict} in embedded arguments would work like type hints telling the framework to do automatic conversion similarly as we do based on function annotations (#2890). That would be a nice feature, but it would also be pretty limited compared to the full argument conversion #2890 supports. This wouldn't allow specifying other types to embedded arguments, and wouldn't benefit normal keyword arguments at all.
Instead of implementing this feature, should we perhaps rather think could we specify types for all arguments? We could, for example, use syntax similar to Python function annotations like this:
*** Keywords ***Normal arguments[Arguments]${first: int}${second: list} # ...Embedded "${args: dict}" would work as well # ...
If we'd use the above syntax, then also this should be supported:
Generic argument/variable types feel a lot better idea to me than being able to use @{list} and &{dict} to tell embedded args types are list/dict. I don't close this issue at least yet, but I remove it from RF 3.2 scope to give more time to think about it. Possible generic argument/variable types would be too big feature for RF 3.2 but could fit RF 3.3.
I forgot we actually have issue #3278 about automatic variable and argument type conversion. The more I think about this, the more I like that enhancement compared to this one. I also don't see any benefits of this issue if that one is implemented.
I still leave this issue open, but unless someone figures good use cases for this syntax if #3278 is implemented, I'll probably close this in the future.
Activity
VVasyaev commentedon Oct 27, 2017
why don't you like the
${type} Evaluate type($arg)?
pekkaklarck commentedon Oct 27, 2017
Could you please clarify what kind of change are you actually proposing? I think I know what you want, but issues should be more explicit.
zachauten commentedon Oct 27, 2017
Currently the only way to embed arguments into a custom library keyword is as a scalar.
If you pass a list variable into the keyword (
test @{list} keyword) it works fine, but it would be nice to be able to embed lists liketest firstarg secondarg thirdarg keyword.To do this you could allow someone writing a decorator for a custom keyword to specify if a variable is a list or a dictionary like
@keyword(test @{list} keyword)or@keyword(test &{dict} keyword)instead of only scalars@keyword(test ${var} keyword)pekkaklarck commentedon Oct 30, 2017
If you'd have a keyword with name
test @{list} keywordand it would be used liketest firstarg secondarg thirdarg keyword, how could Robot know how to split argumentfirstarg secondarg thirdarginto a list? Just using a space as a separator wouldn't work too well if the keyword would then also be used liketest first arg second arg third arg keyword.zachauten commentedon Oct 31, 2017
Sorry, I've been trying to find out more about how Robot parses embedded arguments but I'm not that familiar with it yet. But in the case of just one list being embedded into a keyword couldn't you just use a regex to separate the keyword from the list?
pekkaklarck commentedon Oct 31, 2017
This isn't a technical problem. The problem is deciding about the list or dictionary syntax. You proposed that arguments specified as a string
firstarg secondarg thirdargare parsed to a list["firstarg", "secondarg", "thirdarg"], but thenfirst arg second arg third argis parsed to["first", "arg", "second", "arg", "third", "arg"]which clearly is wrong.zachauten commentedon Oct 31, 2017
Oh, you mean what if you pass strings with spaces in them as elements in the list? Okay I see where that would be a problem.
pekkaklarck commentedon Nov 1, 2017
Yeah, using single space as a separator would mean that values cannot have spaces. I think we could make this work by requiring all items to be quoted and items to be separate with a comma like in
test "first art", "second arg", "third arg" keyword. There would still be a lot of details to decide like do we support both double and single quotes, and should we mandate the variable be surrounded with same quotes in keyword name liketest "@{list}" keyword. Handling dictionaries should have it's own syntax too.pekkaklarck commentedon Nov 3, 2017
Supporting
@{list}and&{dict}with embedded arguments could provide a workaround for the problem initially reported as #1595, and lately again as #2705, when using lists or dictionaries. This would require us to support exact Python syntax liketest ["first art", "second arg", "third arg"] keyword. That's not too nice format if you'd like to pass a list as an argument otherwise, but we could support other formats as well. I'll add this to RF 3.0.3 scope and see how hard this would be to implement.chbndrhnns commentedon Dec 1, 2017
I would very much like the Python syntax for the writing keywords!
pekkaklarck commentedon Mar 15, 2018
RF 3.0.3 has been delayed a lot. Now we want it out ASAP and decided to only include bug fixes in it. I'll thus descope this enhancement to RF 3.1 which we plant to start developing right after RF 3.0.3 is out.
9 remaining items
pekkaklarck commentedon Oct 15, 2019
I'm starting to question is this such a great idea in the end. Basically using
@{list}and&{dict}in embedded arguments would work like type hints telling the framework to do automatic conversion similarly as we do based on function annotations (#2890). That would be a nice feature, but it would also be pretty limited compared to the full argument conversion #2890 supports. This wouldn't allow specifying other types to embedded arguments, and wouldn't benefit normal keyword arguments at all.Instead of implementing this feature, should we perhaps rather think could we specify types for all arguments? We could, for example, use syntax similar to Python function annotations like this:
If we'd use the above syntax, then also this should be supported:
Generic argument/variable types feel a lot better idea to me than being able to use
@{list}and&{dict}to tell embedded args types are list/dict. I don't close this issue at least yet, but I remove it from RF 3.2 scope to give more time to think about it. Possible generic argument/variable types would be too big feature for RF 3.2 but could fit RF 3.3.pekkaklarck commentedon Oct 16, 2019
I forgot we actually have issue #3278 about automatic variable and argument type conversion. The more I think about this, the more I like that enhancement compared to this one. I also don't see any benefits of this issue if that one is implemented.
I still leave this issue open, but unless someone figures good use cases for this syntax if #3278 is implemented, I'll probably close this in the future.
pekkaklarck commentedon Apr 7, 2025
Variable type conversion (#3278) is about to be ready and will be part of RF 7.3. It makes this enhancement redundant.