Skip to content

Support RF 3.2 get_keyword_arguments new format #31

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 28, 2020

Conversation

aaltat
Copy link
Contributor

@aaltat aaltat commented Mar 28, 2020

Fixes #27

@aaltat aaltat merged commit f8fac47 into robotframework:master Mar 28, 2020
@aaltat aaltat deleted the get_keyword_arguments_rf32 branch March 28, 2020 22:56
def __new_arg_spec(self, keyword_name):
kw = self.__get_keyword(keyword_name)
if kw is None:
return [tuple(), ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid return value. The syntax also looks a bit strange when [()] could be used instead, but that's not really relevant.

It would probably be better to handle kw being none in get_keyword_arguments before calling new/old methods. I'm not actually sure what would be a good return value in that case. Probably None to let Robot handle the fact that we don't know the spec. Returning [] would mean that we say the kw accepts no args.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure what should be returned. Other thing that I was considering, that it would be possible to raise an exception. But if None is better from Robot Framework side, let's go with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items in the list returned from get_keyword_names must be strings or tuples with 1-2 items so that the first item is a string.

Isn't it so that kw can be None only if RF calls get_keyword_arguments with some new special value like __special__? It's very unlikely to happen in general, but I guess returning None as an indication that we don't know is the best solution. This could be tested with unit tests but I'm no certain is it worth the effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, None is used for other __special__ values, expect __init__.

if varargs:
args.append(('*{}'.format(varargs), ))
if kwargs:
args.append(('**{}'.format(kwargs), ))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to return other than defaults as tuples. That's ok but also ['mandatory, ('optional', 'default')] is fine. That means only defaults need to be handled differently depending on RF versions and that means some duplication could be removed.

Looking at this code I remember that '{}'.format(value) fails on Python 2 with UnicodeErrorError if value is Unicode and contains non-ASCII stuff. With Python 2 varargs and kwards cannot contain such characters (they aren't even Unicode) but perhaps it would be good to go through the library code and change all '{}'.format(value)s to u'{}'.format(value) or '%s' % value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I thought all are tuples, will change.

  2. I am already forgetting all the Python 2 quirks. Although that is almost same as the from the old format where format() has served pretty well. But it will be consistent with other code to use %s. Just can't wait to ditch Python 2.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance get_keyword_arguments to support new format in Rf 3.2
2 participants