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

Conversation

iDentitY4
Copy link

@iDentitY4 iDentitY4 commented Feb 14, 2024

Implemented #83
When a type is parametrized like List, Union, Tuple, Literal then the type info is removed. See #84

Python 2 support should be working, but i didn't test it yet.
The import of get_type_hints will fall back to __annotations__ on below python 3.5. On python 2 if no robot_types is set then types will be empty.


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.

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

@@ -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

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 add tests for @keyword's types to test/utest/test_keyword_decorator.py and test/libs/KeywordDecorator.py

@@ -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

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

Successfully merging this pull request may close these issues.

2 participants