Reading variables types with Work Items

Hi, I have a new doubt with Work Items, this time in the way we read the files and the type of variables. I have been working with rcc to do this, though is easier with VSCode. I am using one task to read this dictionary in MyVariables.py:

production = {
            "produccion": {
                "a": {
                    "pale ale": {
                        "660ml": "17",
                        "lata": "50a"
                    }
                },
                "c": {
                    "pale ale": {
                        "220ml": "100",
                        "lata": "40"
                    }
                },
                "b": {
                    "rosada": {
                        "500ml": "20",
                        "230ml": "60",
                        "lata": "60"
                    }
                },
                "d": {
                    "especial de halloween 2022": {
                        "250ml": "45",
                        "550ml": "20"
                    }
                }
            }
        }

And add it to a work item. This is not the problem, it is done correctly. Now, I have another robot that will do this:

*** Tasks ***
Example Task
    # Read the work item I just add in the previous task
    ${produccion}=    Get Work Item Variable    produccion
    Log    ${produccion}
    # Retrieving a quantity, which should be a string because in the dict it is between ""
    ${integer}=    Set Variable    ${produccion}[a][pale ale][660ml]
    Log    ${integer}
    # Checking the actual type of the variable
    ${result}=    Evaluate    type(${integer}) is int
    Log    ${result}
    
    ${result}=    Evaluate    type(${integer})
    Log    ${result}
    
    ${status}   ${result}=   Run Keyword and Ignore Error    Evaluate    type(${integer}) is int
    IF    ${result} == True and "${status}"=="PASS"
        Log    *-* The number is integer    console=True
    ELSE
        Log   The number is not integer    WARN
    END   
    
    # Repeting but with other final value
    ${integer2}=    Set Variable    ${produccion}[a][pale ale][lata]
    Log    ${integer2}
   
    #${result}=    Evaluate    type(${integer2})
    # Log    ${result}
    
    ${status}   ${result}=   Run Keyword and Ignore Error    Evaluate    type(${integer2}) is int
    IF    ${result} == True and "${status}"=="PASS"
        Log    *-* The number is integer    console=True
    ELSE
        Log   The number is not integer    WARN
    END

As you can see, I just read and check the state of the variable I want. What I don’t understand is that ${integer} is not a string, it is between quotes in the dictionary in so I believed that it would be a string.

The next case I don’t see the problem, because you can see that ${integer2} should be a string, it is between quotes and also has a letter, but if I check the type it fails (that the reason why those lines are commented). Later while using Run Keyword and Ignore Error it returns this error:

Evaluating expression 'Evaluating expression 'type(50a) is int' failed: SyntaxError: invalid syntax (<string>, line 1) == True and "FAIL"=="PASS"' failed: SyntaxError: invalid syntax (<string>, line 1)

So … I don’t see whats happening, I can’t see the type of that value and if I try to check it fails.
Hope someone can help me. Thanks

In general Robot Framework tries to make the type handling as simple as possible, but this is one case where it is a bit “odd”.

I believe that the value in integer is in fact a str. But Evaluate type(${integer}) does a direct string replacement and replaces the variable name with it’s value. Thus it becomes Evaluate type(100), which ofc returns type int. If you want to get the type of the value actually stored in the variable you need to use different (less known) variantion of variable reference: Evaluate type($integer), which will return the real type str.

Here is a screen shot of similar case:

1 Like

Thanks, I would have never do that :rofl:, I guess that it is something internal from Robotframework in the way to handle variables

1 Like