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

Positional only argument support with Python keywords #3695

Closed
pekkaklarck opened this issue Oct 4, 2020 · 3 comments
Closed

Positional only argument support with Python keywords #3695

pekkaklarck opened this issue Oct 4, 2020 · 3 comments

Comments

@pekkaklarck
Copy link
Member

Python 3.8 added support for positional-only arguments. They have some nice usages with Python code but I doubt they are that important with RF libraries. Anyway, we should support them or at least make sure things don't break strangely. I also believe we should add the support already in RF 4.0 because changes affect our model objects that may be exposed via Libdoc APIs and changes later would cause backwards compatibility problems.

This issue covers supporting positional-only arguments only with Python based keywords. Separate issue can be submitted about supporting them with dynamic libraries that often are implemented with Python and could benefit from the support as well. We could also support them with user keywords if someone comes up with valid use cases.

@pekkaklarck pekkaklarck added this to the v4.0 milestone Oct 4, 2020
pekkaklarck added a commit that referenced this issue Oct 7, 2020
This eases migrating to inspect.signature with Py3 code to be able to
support positional-only arguments (#3695). Less conditional code
simplifies the logic many other ways as well.
pekkaklarck added a commit that referenced this issue Oct 7, 2020
inspect.getfullargspec doesn't support positional-only arguments
(#3695). This commit doesn't yet enable that support.
pekkaklarck added a commit that referenced this issue Oct 7, 2020
Changes:
- Add `positional_only` attribute.
- Rename `positional` to `positional_or_named`.
- Rename other attributes for consistency.
- Enhance ArgInfo to handle positional-only args.

Actual positional-only argument support is still to-do.

See #3695 for more details.
pekkaklarck added a commit that referenced this issue Oct 7, 2020
Adding this support allowed removing ArgumentSpec.supports_named and
in the end more code was removed than added.
@pekkaklarck
Copy link
Member Author

pekkaklarck commented Oct 7, 2020

This is now done otherwise but documentation is still missing.

@pekkaklarck
Copy link
Member Author

pekkaklarck commented Oct 7, 2020

I decided to implement this so that if a keyword is implemented like

def example(posonly, /, normal=None):
    print(posonly, normal)

and called like

Example    posonly=value

the posonly argument gets a literal value posonly=value. An alternative would have been making this an error but I decided not to do that because using e.g. what=ever would also mean passing that value as-is. Never needing to escape = with positional only arguments can be considered a feature. This is nevertheless an error:

Example    normal=value    posonly=value

@pekkaklarck
Copy link
Member Author

pekkaklarck commented Oct 7, 2020

Docs are written and this issue can be considered done.

A nice benefit of adding positional-only arguments was that it allowed removing supports_named attribute from the ArgumentSpec object. It was previously used with Java based libraries because we don't see the real argument names with them and thus couldn't support the named argument syntax with them. Now these arguments are marked positional-only and that has the exact same effect. Libdoc still shows does a library support named arguments in its outputs but that could be removed. It needs a separate issue, though.

vokiput pushed a commit to vokiput/robotframework that referenced this issue Dec 27, 2020
This eases migrating to inspect.signature with Py3 code to be able to
support positional-only arguments (robotframework#3695). Less conditional code
simplifies the logic many other ways as well.
vokiput pushed a commit to vokiput/robotframework that referenced this issue Dec 27, 2020
inspect.getfullargspec doesn't support positional-only arguments
(robotframework#3695). This commit doesn't yet enable that support.
vokiput pushed a commit to vokiput/robotframework that referenced this issue Dec 27, 2020
Changes:
- Add `positional_only` attribute.
- Rename `positional` to `positional_or_named`.
- Rename other attributes for consistency.
- Enhance ArgInfo to handle positional-only args.

Actual positional-only argument support is still to-do.

See robotframework#3695 for more details.
vokiput pushed a commit to vokiput/robotframework that referenced this issue Dec 27, 2020
Adding this support allowed removing ArgumentSpec.supports_named and
in the end more code was removed than added.
vokiput pushed a commit to vokiput/robotframework that referenced this issue Dec 27, 2020
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