Skip to content

Commit 8d18543

Browse files
committed
Fix keyword with decorator and deco arguments
1 parent 44cb737 commit 8d18543

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

atest/DynamicTypesAnnotationsLibrary.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
2-
from typing import List, Union, NewType, Optional
2+
from functools import wraps
3+
from typing import List, Union, NewType, Optional, Tuple
34

45
from robot.api import logger
56

@@ -10,6 +11,21 @@
1011
penum = Enum("penum", "ok")
1112

1213

14+
def _my_deco(old_args: Tuple[str, str], new_args: Tuple[str, str]):
15+
def actual_decorator(method):
16+
@wraps(method)
17+
def wrapper(*args, **kwargs):
18+
for index, old_arg in enumerate(old_args):
19+
logger.warn(
20+
f"{old_arg} has deprecated, use {new_args[index]}",
21+
)
22+
return method(*args, **kwargs)
23+
24+
return wrapper
25+
26+
return actual_decorator
27+
28+
1329
class CustomObject(object):
1430

1531
def __init__(self, x, y):
@@ -126,3 +142,8 @@ def enum_conversion(self, param: Optional[penum] = None):
126142
logger.info(f'OK {param}')
127143
logger.info(param.ok)
128144
return f'OK {param}'
145+
146+
@keyword
147+
@_my_deco(old_args=("arg1", ), new_args=("arg2", ))
148+
def keyword_with_deco_and_signature(self, arg1: bool = False, arg2: bool = False):
149+
return f"{arg1}: {type(arg1)}, {arg2}: {type(arg2)}"

src/robotlibcore.py

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ class KeywordBuilder(object):
164164

165165
@classmethod
166166
def build(cls, function):
167+
if not PY2:
168+
function = inspect.unwrap(function)
167169
return KeywordSpecification(
168170
argument_specification=cls._get_arguments(function),
169171
documentation=inspect.getdoc(function) or '',

utest/test_get_keyword_types.py

+6
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,9 @@ def test_keyword_self_and_types(lib_types):
239239
def test_keyword_self_and_keyword_only_types(lib_types):
240240
types = lib_types.get_keyword_types('keyword_self_and_keyword_only_types')
241241
assert types == {'varargs': int, 'other': bool, 'kwargs': int}
242+
243+
244+
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
245+
def test_keyword_with_decorator_arguments(lib_types):
246+
types = lib_types.get_keyword_types('keyword_with_deco_and_signature')
247+
assert types == {'arg1': bool, 'arg2': bool}

0 commit comments

Comments
 (0)