Skip to content

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

Closed

Description

@pekkaklarck

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'}

Activity

  1. added this to the v6.1 milestone on Mar 28, 2023
  2. pekkaklarck commented on Mar 30, 2023

    @pekkaklarck
    MemberAuthor

    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.

  3. added theissue type on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions