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

Support named-only arguments with user keywords #2896

Closed
pekkaklarck opened this issue Jul 7, 2018 · 3 comments

Comments

@pekkaklarck
Copy link
Member

commented Jul 7, 2018

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}
    # ...

@pekkaklarck pekkaklarck added this to the v3.1 milestone Jul 7, 2018

pekkaklarck added a commit that referenced this issue Jul 7, 2018
Support named-only arguments with user keywords.
This implementation ought to work, but a little cleanup wouldn't hurt.
Documentation in the User Guide is totally missing as well. See #2896.
@pekkaklarck

This comment has been minimized.

Copy link
Member Author

commented Jul 7, 2018

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

@aaltat

This comment has been minimized.

Copy link
Contributor

commented Jul 8, 2018

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

@pekkaklarck

This comment has been minimized.

Copy link
Member Author

commented Jul 8, 2018

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.

pekkaklarck added a commit that referenced this issue Jul 11, 2018
Libdoc: Support named-only args.
Related to issues about adding named-only arguments support to
Python libraries (#2555), dynamic libraries (#2897) and user
keywords (#2896).
pekkaklarck added a commit that referenced this issue Jul 18, 2018
Add @Brian-Williams to AUTHORS.txt
Brian contributed named-only arguments support for Python 3 libraries
(#2555), which was a motivation to add named-only arguments support
also to user keywords (#2896) and to dynamic libraries (#2897).
@pekkaklarck pekkaklarck referenced this issue Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.