Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion atest/DynamicTypesAnnotationsLibrary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum
from typing import List, Union, NewType, Optional
from functools import wraps
from typing import List, Union, NewType, Optional, Tuple

from robot.api import logger

Expand All @@ -10,6 +11,21 @@
penum = Enum("penum", "ok")


def _my_deco(old_args: Tuple[str, str], new_args: Tuple[str, str]):
def actual_decorator(method):
@wraps(method)
def wrapper(*args, **kwargs):
for index, old_arg in enumerate(old_args):
logger.warn(
f"{old_arg} has deprecated, use {new_args[index]}",
)
return method(*args, **kwargs)

return wrapper

return actual_decorator


class CustomObject(object):

def __init__(self, x, y):
Expand Down Expand Up @@ -126,3 +142,8 @@ def enum_conversion(self, param: Optional[penum] = None):
logger.info(f'OK {param}')
logger.info(param.ok)
return f'OK {param}'

@keyword
@_my_deco(old_args=("arg1", ), new_args=("arg2", ))
def keyword_with_deco_and_signature(self, arg1: bool = False, arg2: bool = False):
return f"{arg1}: {type(arg1)}, {arg2}: {type(arg2)}"
2 changes: 2 additions & 0 deletions src/robotlibcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class KeywordBuilder(object):

@classmethod
def build(cls, function):
if not PY2:
function = inspect.unwrap(function)
return KeywordSpecification(
argument_specification=cls._get_arguments(function),
documentation=inspect.getdoc(function) or '',
Expand Down
6 changes: 6 additions & 0 deletions utest/test_get_keyword_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,9 @@ def test_keyword_self_and_types(lib_types):
def test_keyword_self_and_keyword_only_types(lib_types):
types = lib_types.get_keyword_types('keyword_self_and_keyword_only_types')
assert types == {'varargs': int, 'other': bool, 'kwargs': int}


@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
def test_keyword_with_decorator_arguments(lib_types):
types = lib_types.get_keyword_types('keyword_with_deco_and_signature')
assert types == {'arg1': bool, 'arg2': bool}