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

Implement get_keyword_types for non parameterized types #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/robotremoteserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def getfullargspec(func):
PY2, PY3 = False, True
unicode = str
long = int
try:
from typing import get_type_hints
except ImportError:
get_type_hints = lambda func: func.__annotations__


__all__ = ['RobotRemoteServer', 'stop_remote_server', 'test_remote_server']
Expand Down Expand Up @@ -87,6 +91,7 @@ def _register_functions(self, server):
server.register_function(self.get_keyword_names)
server.register_function(self.run_keyword)
server.register_function(self.get_keyword_arguments)
server.register_function(self.get_keyword_types)
server.register_function(self.get_keyword_documentation)
server.register_function(self.stop_remote_server)

Expand Down Expand Up @@ -182,6 +187,11 @@ def get_keyword_arguments(self, name):
if name == 'stop_remote_server':
return []
return self._library.get_keyword_arguments(name)

def get_keyword_types(self, name):
Copy link

Choose a reason for hiding this comment

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

Add a dynamic_method to DynamicRemoteLibrary for get_keyword_types

if name == 'stop_remote_server':
return {}
return self._library.get_keyword_types(name)

def get_keyword_documentation(self, name):
if name == 'stop_remote_server':
Expand Down Expand Up @@ -322,6 +332,24 @@ def get_keyword_arguments(self, name):
if kwargs:
args.append('**%s' % kwargs)
return args

def get_keyword_types(self, name):
Copy link

Choose a reason for hiding this comment

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

We should add some tests to test/utest/test_dynamicargsdoctags.py and test/utest/test_argsdocs.py

if __name__ == "__init__":
return {}
kw = self._get_keyword(name)
if getattr(kw, "robot_types", None):
robot_types = kw.robot_types
Copy link

Choose a reason for hiding this comment

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

We should support when robot_types is a list since @keyword supports a list or dict for types

https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#specifying-argument-types-using-keyword-decorator

Copy link

Choose a reason for hiding this comment

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

We should add tests for @keyword's types to test/utest/test_keyword_decorator.py and test/libs/KeywordDecorator.py

elif sys.version_info < (3,):
robot_types = {}
else:
robot_types = get_type_hints(kw)

for arg_name, arg_type in robot_types.items():
if hasattr(arg_type, '__args__'):
del robot_types[arg_name]
Copy link

Choose a reason for hiding this comment

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

Avoid deleting from the robot_types while iterating

From https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects

The objects returned by dict.keys(), dict.values() and dict.items() are view objects

Iterating views while adding or deleting entries in the dictionary may raise a RuntimeError or fail to iterate over all entries.

else:
robot_types[arg_name] = arg_type.__name__
return robot_types

def get_keyword_documentation(self, name):
if name == '__intro__':
Expand Down