Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support creating assigned variable name based on another variable like ${${var}} = Keyword #4545

Closed
zastress opened this issue Nov 25, 2022 · 4 comments

Comments

@zastress
Copy link

Apparently, it is not possible do return values into nested variables in RF, for cases like:

${x${y}} =    Keyword
${x}[a] =    Keyword

These can be quite handy aswell while using FOR loops, to populate values inside, like:

FOR    ${INDEX}    IN RANGE    1    4
        Keyword1    ${user${INDEX}-email}    ${user${INDEX}-fullname}    gender=${INDEX}
        ${short-id-${INDEX}}    API - Get User ID    ${user${INDEX}-fullname}
END
@pekkaklarck
Copy link
Member

This is true. Notice, though, that

${x ${y}} =    Keyword

and

${x}[a] =    Keyword

are totally different features and thus need separate issues. The former is about creating the name of the assigned variable dynamically and the latter is about setting an item to a list, a dictionary, or anything else that has __setitem__. Both would be useful, but their implementation is different and most likely the latter is easier. I also consider the latter more useful and thus more important.

The example in the description uses the ${x${y}} style so I guess we could consider this issue to be dedicated to that. The other enhancement then needs a separate issue. I can submit it myself.

@pekkaklarck
Copy link
Member

The proposed

${x ${y}} =    Keyword

syntax is interesting because something like that isn't directly possible in Python. You can do it with setattr, but that doesn't really work on module level.

Until this functionality is implemented, you ought to be able to use the Set Local Variable keyword as a workaround:

${ret} =    Keyword
Set Local Variable    $x ${y}    ${ret}

@pekkaklarck
Copy link
Member

pekkaklarck commented Nov 25, 2022

The proposed

${x}[a] =    Keyword

syntax is the same as

x[a] = keyword()

in Python. For it the current workaround is using Collections keywords to add items to a dictionary or list, depending on the type of ${x}:

${ret} =    Keyword
Set To Dictionary    ${x}    a    ${ret}

@pekkaklarck pekkaklarck changed the title Unable to return values from keywords inside nested variables Support creating assigned variable name dynamically like ${x ${y}} = Keyword Nov 25, 2022
@pekkaklarck pekkaklarck added this to the v6.1 milestone Nov 25, 2022
@pekkaklarck
Copy link
Member

New #4546 now covers the item assignment syntax ${x}[a] = Keyword. I added both of these issues initially to RF 6.1 milestone.

@yanne yanne modified the milestones: v6.1, v6.2 Jan 3, 2023
@pekkaklarck pekkaklarck modified the milestones: v6.2, v7.0 Jun 2, 2023
@pekkaklarck pekkaklarck self-assigned this Oct 17, 2023
@pekkaklarck pekkaklarck changed the title Support creating assigned variable name dynamically like ${x ${y}} = Keyword Support creating assigned variable name based on another variable like ${${var}} = Keyword Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants