Skip to content

Commit 1fca155

Browse files
committed
Support keyword only arguments for get types
1 parent 958e3cd commit 1fca155

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

atest/DynamicTypesAnnotationsLibrary.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ def keyword_only_arguments(self, *varargs, some='value'):
8181
@keyword
8282
def keyword_only_arguments_many(self, *varargs, some='value', other=None):
8383
return f'{some}: {type(some)}, {other}: {type(other)}, {varargs}: {type(varargs)}'
84+
85+
@keyword
86+
def keyword_mandatory_and_keyword_only_arguments(self, arg: int, *vararg, some=True):
87+
return f'{arg}, {vararg}, {some}'

src/robotlibcore.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,14 @@ def __get_typing_hints(self, method):
204204
return hints
205205

206206
def __join_defaults_with_types(self, method, types):
207-
_, defaults, _, _, _ = self.__get_arg_spec(method)
207+
_, defaults, _, _, kwonlydefaults = self.__get_arg_spec(method)
208208
for name, value in defaults:
209209
if name not in types and isinstance(value, (bool, type(None))):
210210
types[name] = type(value)
211+
if kwonlydefaults:
212+
for name, value in kwonlydefaults.items():
213+
if name not in types and isinstance(value, (bool, type(None))):
214+
types[name] = type(value)
211215
return types
212216

213217
def get_keyword_source(self, keyword_name):

utest/test_get_keyword_types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,21 @@ def test_init_args_with_annotation(lib_types):
169169
def test_exception_in_annotations(lib_types):
170170
types = lib_types.get_keyword_types('keyword_exception_annotations')
171171
assert types == {'arg': 'NotHere'}
172+
173+
174+
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
175+
def test_keyword_only_arguments(lib_types):
176+
types = lib_types.get_keyword_types('keyword_only_arguments')
177+
assert types == {}
178+
179+
180+
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
181+
def test_keyword_only_arguments_many(lib_types):
182+
types = lib_types.get_keyword_types('keyword_only_arguments_many')
183+
assert types == {'other': type(None)}
184+
185+
186+
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
187+
def test_keyword_only_arguments_many(lib_types):
188+
types = lib_types.get_keyword_types('keyword_mandatory_and_keyword_only_arguments')
189+
assert types == {'arg': int, 'some': bool}

0 commit comments

Comments
 (0)