Skip to content

Commit 08a431d

Browse files
committed
Fixed varargs and kwargs typing information
1 parent 6e58b7c commit 08a431d

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

atest/DynamicTypesAnnotationsLibrary.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,7 @@ def keyword_self_and_types(self: 'DynamicTypesAnnotationsLibrary', mandatory: st
111111
return True
112112

113113
@keyword
114-
def keyword_self_and_keyword_only_types(x: 'DynamicTypesAnnotationsLibrary', mandatory, *varargs: int, other: bool, **kwargs: Dict[str, int]):
115-
return True
114+
def keyword_self_and_keyword_only_types(x: 'DynamicTypesAnnotationsLibrary', mandatory, *varargs: int, other: bool,
115+
**kwargs: int):
116+
return (f'{mandatory}: {type(mandatory)}, {varargs}: {type(varargs)}, '
117+
f'{other}: {type(other)}, {kwargs}: {type(kwargs)}')

atest/tests_types.robot

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ Keyword Only Arguments Without VarArg
6262
${return} = DynamicTypesAnnotationsLibrary.Keyword Only Arguments No Vararg other=tidii
6363
Should Match ${return} tidii: <class 'str'>
6464

65+
Varargs and KeywordArgs With Typing Hints
66+
[Tags] py3
67+
${return} = DynamicTypesAnnotationsLibrary.Keyword Self And Keyword Only Types
68+
... this_is_mandatory # mandatory argument
69+
... 1 2 3 4 # varargs
70+
... other=True # other argument
71+
... key1=1 key2=2 # kwargs
72+
Should Match ${return}
73+
... this_is_mandatory: <class 'str'>, (1, 2, 3, 4): <class 'tuple'>, True: <class 'bool'>, {'key1': 1, 'key2': 2}: <class 'dict'>
74+
6575
*** Keywords ***
6676
Import DynamicTypesAnnotationsLibrary In Python 3 Only
6777
${py3} = DynamicTypesLibrary.Is Python 3

src/robotlibcore.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,6 @@ def get_typing_hints(self):
232232
# remove return and self statements
233233
if arg not in self:
234234
hints.pop(arg)
235-
if self.varargs and arg in self.varargs:
236-
hints['*%s' % arg] = hints[arg]
237-
del hints[arg]
238-
if self.kwargs and arg in self.kwargs:
239-
hints['**%s' % arg] = hints[arg]
240-
del hints[arg]
241235
return hints
242236

243237
def _format_positional(self, positional, defaults):

utest/test_get_keyword_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,4 @@ def test_keyword_self_and_types(lib_types):
210210
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
211211
def test_keyword_self_and_keyword_only_types(lib_types):
212212
types = lib_types.get_keyword_types('keyword_self_and_keyword_only_types')
213-
assert types == {'*varargs': int, 'other': bool, '**kwargs': Dict[str, int]}
213+
assert types == {'varargs': int, 'other': bool, 'kwargs': int}

0 commit comments

Comments
 (0)