Skip to content

Support literal list/dict syntax when using @{list} and &{dict} as embedded arguments #2699

Closed as not planned

Description

@zachauten

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.

Activity

  1. VVasyaev commented on Oct 27, 2017

    @VVasyaev
    Contributor

    why don't you like the
    ${type} Evaluate type($arg)
    ?

  2. pekkaklarck commented on Oct 27, 2017

    @pekkaklarck
    Member

    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.

  3. zachauten commented on Oct 27, 2017

    @zachauten
    Author

    Currently the only way to embed arguments into a custom library keyword is as a scalar.

    @keyword("test ${var} keyword")
    def test(self, *var):
    

    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)

  4. pekkaklarck commented on Oct 30, 2017

    @pekkaklarck
    Member

    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.

  5. zachauten commented on Oct 31, 2017

    @zachauten
    Author

    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?

  6. pekkaklarck commented on Oct 31, 2017

    @pekkaklarck
    Member

    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.

  7. zachauten commented on Oct 31, 2017

    @zachauten
    Author

    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.

  8. pekkaklarck commented on Nov 1, 2017

    @pekkaklarck
    Member

    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.

  9. pekkaklarck commented on Nov 3, 2017

    @pekkaklarck
    Member

    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.

  10. added this to the milestone on Nov 3, 2017
  11. chbndrhnns commented on Dec 1, 2017

    @chbndrhnns

    I would very much like the Python syntax for the writing keywords!

  12. pekkaklarck commented on Mar 15, 2018

    @pekkaklarck
    Member

    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.

  13. removed this from the milestone on Mar 15, 2018
  14. 9 remaining items

  15. added this to the v.3.2 milestone on Oct 8, 2018
  16. added
    help wanted
    and removed on Mar 5, 2019
  17. pekkaklarck commented on Oct 15, 2019

    @pekkaklarck
    Member

    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:

    *** Variables ***
    ${EXAMPLE 1: list}     [1, 2, 3, 4, 5]
    @{EXAMPLE 2: int}      1    2    3    4    5

    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.

  18. removed this from the v3.2 milestone on Oct 16, 2019
  19. pekkaklarck commented on Oct 16, 2019

    @pekkaklarck
    Member

    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.

  20. pekkaklarck commented on Apr 7, 2025

    @pekkaklarck
    Member

    Variable type conversion (#3278) is about to be ready and will be part of RF 7.3. It makes this enhancement redundant.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions