Skip to content

Support named-only arguments with user keywords #2896

Closed

Description

@pekkaklarck

Issue #2555 adds support for named-only arguments, or keyword-only arguments if we use Python terminology, when using Python based keywords. This functionality would be useful also with user keywords and having consistent feature set among different keywords is important as well.

For most part we can design this functionality based on how it works with Python. In practice this means that we could have keywords like this

*** Keywords ***
Mandatory named-only argument
    [Arguments]    ${normal}    @{varargs}    ${named}
    # ...

Named-only argument with default value
    [Arguments]    ${normal}    @{varargs}    ${named}=default
    # ...

that would require passing the argument after varargs using the named-arguments syntax like named=value.

The only real question is how to specify that named-only arguments are used when there are no varargs. Python uses a lone * for that, and I propose we use @{} similarly. Alternatively we could use just @, but somehow I feel the former better. For example, the following keyword would accept no positional arguments and would require the named-only argument passed like named=value.

*** Keywords ***
Example
    [Arguments]    @{}    ${named}
    # ...

If we used @, the same keyword would look like this instead:

*** Keywords ***
Example
    [Arguments]    @    ${named}
    # ...

Activity

  1. added this to the v3.1 milestone on Jul 7, 2018
  2. pekkaklarck commented on Jul 7, 2018

    @pekkaklarck
    MemberAuthor

    This feature has now been implemented but documentation in the User Guide is still missing.

  3. aaltat commented on Jul 8, 2018

    @aaltat
    Contributor

    I would prefer @ over @{} but I don't feel strongly about the matter.

  4. pekkaklarck commented on Jul 8, 2018

    @pekkaklarck
    MemberAuthor

    I kind of like @ better than @{} as well, but when used with other arguments @ looks a bit weird. For example, the example above with @{} ${named} looks somehow better to me than @ ${named}. A problem with the latter is that Robot syntax highlighter here on GitHub doesn't recognize @ as an argument and, for example, PyCharm works the same. These can be fixed eventually, but @{} working out-of-the box is nice.

  5. added a commit that references this issue on Jul 11, 2018
  6. added a commit that references this issue on Jul 18, 2018
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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions