Empty list or dict with VAR

Hi !

For a while now I have been using and have replaced VAR syntax this way in my code (Robocop: off is used as there is no value assigned to my variable):

VAR    @{list}   # robocop: off

But I’m wondering how to handle easily/properly the fact that an ${EMPTY} value is assigned, as the following will create a list [ ’ ', ‘aaa’, ‘bbb’] instead of [‘aaa’, ‘bbb’]):

VAR    @{list}    ${EMPTY}
FOR    ${i}    IN    aaa    bbb
    Append To List    ${list}    ${i}
    Log    ${list}
END  

Of course I can stack a Remove from List ${list} ${EMPTY} after the VAR definition, but would be interested if there are some more suitable solutions.

Thanks!
Charlie

So, you need to wait for a fix on robocop ?
I don’t use robocop, but that seems it is missing an update.

1 Like

@CharlieScene Why don’t you just use VAR @{list} as you did in your first example? That creates an empty list. See Robot Framework User Guide
Or is the Robocop extension complaining that the variable is empty? In that case just use the RobotCode extension from Daniel Biehl :grinning:.

2 Likes

Hi,

No, no problem with Robocop actually. And I use Robotcode already.

Thing behind this is that I import the xml file in third party (Jira/Xray) through API and the fact that the @{list} variable is empty (in fact has no tag in the xml file) gives back an error 500.

So I was simply thinking of adding ${EMPTY} to definition (that allow import), but this add this empty item in the list that I don’t need.
Hence the question about managing this.

I already have Xray support on this but I’m not sure about the outcome of this syntax support in short notice.

Sorry I wasn’t that clear :sweat_smile:

Regards
Charlie

Note that @{EMPTY} and &{EMPTY} can be used to assign empty lists / dicts.

3 Likes

Wow thanks!
Exactly what I was searching as solution :slightly_smiling_face:
That’s perfect!

Regards
Charlie

1 Like