Skip to content

Simpler syntax to create lists, dicts, and other collections as arguments to keywords #4478

Description

@pekkaklarck

Robot's automatic argument conversion (#2890) makes it possible to have a keywords like

def accept_list(arg: list):
    ...

def accept_dict(arg: dict):
    ...

and call them so that argument are Python literals

Accept List    ['list', 'items', 'here']
Accept Dict    {'key': 'value', 'another': 'item'}

This is pretty convenient, but needing to use Python syntax is a bit ugly in general and especially annoying when using embedded arguments that are supposed to enhance readability:

Select animals ['cat', 'dog'] from list

I propose we enhance argument conversion so that we support also the following syntax:

Accept List    list, items, here
Accept Dict    key=value, another=item

The high level semantics would be as follows:

  • Separator between items is a comma and a space. This allows using commas in values like first, second,with,commas, third. Having a comma followed by a space in the value wouldn't be possible.
  • We could allow using a semicolon and a space as an alternative separator. In that case we'd use the separator that's encountered first. This would allow usages like first; second, with, commas followed by spaces; third.
  • With dictionaries the separator between key and value is =. This is the syntax we use also when creating &{dict} variables.
  • Values are considered strings by default. This can be changed by using generics (Convert and validate collection contents when using generics in type hints #4433) and TypedDict (Convert and validate TypedDict items #4477).
  • Because this would be handled by type convertors, variables would have been resolved already earlier. That means that something like ${1}, ${2} wouldn't create a list of integers. See the above point for alternatives.
  • Also escapes are handled before type conversion. That makes it impossible to use something like first, second\,with\,commas for escaping commas in values.

This enhancement would ease using collections a lot especially if #4433 and #4477 are implemented. If we agree above semantics are fine, implementation would also be pretty easy. I thus add this to RF 5.1 scope even though the release is already late.

Activity

  1. added this to the v5.1 milestone on Sep 26, 2022
  2. xylix commented on Sep 26, 2022

    @xylix
    Contributor

    Select animals cat, dog from list

    After the proposed change should this work and would it be more readable than the old one? I would personally expect some sort of separator around the list items.

  3. pekkaklarck commented on Sep 27, 2022

    @pekkaklarck
    MemberAuthor

    Select animals cat, dog from list isn't great, but it's certainly better for non-programmers than Select animals ['cat', 'dog'] from list.

  4. pekkaklarck commented on Sep 27, 2022

    @pekkaklarck
    MemberAuthor

    Based on the discussion on Slack, it seems this isn't considered that important and there are concerns about the syntax. Let's descope this from RF 5.1 and think about this again later.

  5. modified the milestones: v5.1, v5.2 on Sep 27, 2022
  6. modified the milestones: v6.1, on Jan 4, 2023
  7. modified the milestones: , v7.0 on Jun 2, 2023
  8. modified the milestones: v7.0, v8.0 on Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions