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

Items are not converted when using generics like list[int] and passing object, not string #4705

Closed
pekkaklarck opened this issue Mar 28, 2023 · 1 comment

Comments

@pekkaklarck
Copy link
Member

pekkaklarck commented Mar 28, 2023

We added support for converting items with generics like list[int] and dict[str, int] in RF 6.0 (#4433). There unfortunately is a bug that it only works when passing values as string literals, not as actual object. For example, using this example from our Slack:

def sum_values(values_dict: dict[str, int]) -> int:
    values_sum: int = 0
    for _, value in values_dict.items():
        values_sum += value
    return values_sum

like:

&{dict} =    Create Dictionary    spam    11    eggs    22
${sum} =    Sum Values    ${dict}

fails with:

TypeError: unsupported operand type(s) for +=: 'int' and 'str'`.

Using the example with a dictionary literal works fine:

${sum} =    Sum Values    {'spam': '11', 'eggs': '22'}
@pekkaklarck
Copy link
Member Author

This was implemented so that all nested values are always converted and the top level object is recreated. That has a possible problem, that the actual argument passed to the keyword isn't the same instance that was used and mutating the value thus has no effect. Another problem is that if nested items already have a correct type, conversion can take some time and memory at least with bigger objects. It might be better to change the implementation so that if nested item types are as expected, no conversion is done. That's just somewhat more complicated and would probably benefit from a little refactoring to avoid duplication.

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

1 participant