Skip to content

Commit dae82d0

Browse files
committed
Fixed code and utest
1 parent d415f92 commit dae82d0

6 files changed

Lines changed: 21 additions & 45 deletions

atest/DynamicTypesAnnotationsLibrary.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def keyword_with_webdriver(self, arg: CustomObject):
5555
return arg
5656

5757
@keyword
58-
def keyword_default_and_annotation(self: 'DynamicTypesAnnotationsLibrary', arg1: int, arg2=False) -> str:
58+
def keyword_default_and_annotation(self: 'DynamicTypesAnnotationsLibrary', arg1: int, arg2: Union[bool, str] = False) -> str:
5959
return '%s: %s, %s: %s' % (arg1, type(arg1), arg2, type(arg2))
6060

6161
@keyword(types={'arg': str})
@@ -67,7 +67,7 @@ def keyword_robot_types_disabled_and_annotations(self, arg: int):
6767
return '%s: %s' % (arg, type(arg))
6868

6969
@keyword(types={'arg1': str})
70-
def keyword_robot_types_and_bool_defaults(self, arg1, arg2=False):
70+
def keyword_robot_types_and_bool_hint(self, arg1, arg2: bool):
7171
return '%s: %s, %s: %s' % (arg1, type(arg1), arg2, type(arg2))
7272

7373
@keyword
@@ -87,7 +87,9 @@ def keyword_only_arguments_no_vararg(self, *, other):
8787
return f'{other}: {type(other)}'
8888

8989
@keyword
90-
def keyword_only_arguments_many_positional_and_default(self: 'DynamicTypesAnnotationsLibrary', *varargs, one, two, three, four=True, five=None, six=False):
90+
def keyword_only_arguments_many_positional_and_default(self: 'DynamicTypesAnnotationsLibrary', *varargs, one, two,
91+
three, four: Union[int, str] = 1, five=None,
92+
six: Union[bool, str] = False):
9193
return f'{varargs}, {one}, {two}, {three}, {four}, {five}, {six}'
9294

9395
@keyword
@@ -99,7 +101,7 @@ def keyword_only_arguments_many(self, *varargs, some='value', other=None):
99101
return f'{some}: {type(some)}, {other}: {type(other)}, {varargs}: {type(varargs)}'
100102

101103
@keyword
102-
def keyword_mandatory_and_keyword_only_arguments(self, arg: int, *vararg, some=True):
104+
def keyword_mandatory_and_keyword_only_arguments(self, arg: int, *vararg, some: bool):
103105
return f'{arg}, {vararg}, {some}'
104106

105107
@keyword

atest/DynamicTypesLibrary.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ def keyword_default_types(self, arg=None):
5353
def keyword_many_default_types(self, arg1=1, arg2='Foobar'):
5454
return arg1, arg2
5555

56-
@keyword
57-
def keyword_booleans(self, arg1=True, arg2=False):
58-
return '%s: %s, %s: %s' % (arg1, type(arg1), arg2, type(arg2))
59-
6056
@keyword
6157
def keyword_none(self, arg=None):
6258
return '%s: %s' % (arg, type(arg))

src/robotlibcore.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def get_keyword_types(self, keyword_name):
124124
return types
125125
if not types:
126126
types = self.__get_typing_hints(method)
127-
types = self.__join_defaults_with_types(method, types)
127+
types.pop('return', None)
128128
return types
129129

130130
def __get_keyword(self, keyword_name):
@@ -143,16 +143,6 @@ def __get_typing_hints(self, method):
143143
spec = ArgumentSpec.from_function(method)
144144
return spec.get_typing_hints()
145145

146-
def __join_defaults_with_types(self, method, types):
147-
spec = ArgumentSpec.from_function(method)
148-
for name, value in spec.defaults:
149-
if name not in types and isinstance(value, (bool, type(None))):
150-
types[name] = type(value)
151-
for name, value in spec.kwonlydefaults:
152-
if name not in types and isinstance(value, (bool, type(None))):
153-
types[name] = type(value)
154-
return types
155-
156146
def get_keyword_source(self, keyword_name):
157147
method = self.__get_keyword(keyword_name)
158148
path = self.__get_keyword_path(method)

utest/test_get_keyword_source.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_location_in_class(lib, lib_path_components):
5252
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
5353
def test_decorator_wrapper(lib_types, lib_path_types):
5454
source = lib_types.get_keyword_source('keyword_wrapped')
55-
assert source == '%s:76' % lib_path_types
55+
assert source == '%s:72' % lib_path_types
5656

5757

5858
def test_location_in_class_custom_keyword_name(lib, lib_path_components):
@@ -81,7 +81,7 @@ def test_no_path_and_no_line_number(lib, when):
8181

8282
def test_def_in_decorator(lib_types, lib_path_types):
8383
source = lib_types.get_keyword_source('keyword_with_def_deco')
84-
assert source == '%s:70' % lib_path_types
84+
assert source == '%s:66' % lib_path_types
8585

8686

8787
def test_error_in_getfile(lib, when):

utest/test_get_keyword_types.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_types_disabled(lib):
3333

3434
def test_keyword_types_and_bool_default(lib):
3535
types = lib.get_keyword_types('keyword_robot_types_and_bool_default')
36-
assert types == {'arg1': str, 'arg2': bool}
36+
assert types == {'arg1': str}
3737

3838

3939
def test_one_keyword_type_defined(lib):
@@ -51,14 +51,9 @@ def test_not_keyword(lib):
5151
lib.get_keyword_types('not_keyword')
5252

5353

54-
def test_keyword_booleans(lib):
55-
types = lib.get_keyword_types('keyword_booleans')
56-
assert types == {'arg1': bool, 'arg2': bool}
57-
58-
5954
def test_keyword_none(lib):
6055
types = lib.get_keyword_types('keyword_none')
61-
assert types == {'arg': type(None)}
56+
assert types == {}
6257

6358

6459
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
@@ -79,11 +74,6 @@ def test_multiple_types(lib_types):
7974
assert types == {'arg': Union[List, None]}
8075

8176

82-
def test_keyword_with_default_type(lib):
83-
types = lib.get_keyword_types('keyword_default_types')
84-
assert types == {'arg': type(None)}
85-
86-
8777
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
8878
def test_keyword_new_type(lib_types):
8979
types = lib_types.get_keyword_types('keyword_new_type')
@@ -123,7 +113,7 @@ def test_keyword_with_annotation_external_class(lib_types):
123113
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
124114
def test_keyword_with_annotation_and_default(lib_types):
125115
types = lib_types.get_keyword_types('keyword_default_and_annotation')
126-
assert types == {'arg1': int, 'arg2': bool}
116+
assert types == {'arg1': int, 'arg2': Union[bool, str]}
127117

128118

129119
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
@@ -140,13 +130,13 @@ def test_keyword_with_robot_types_disbaled_and_annotations(lib_types):
140130

141131
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
142132
def test_keyword_with_robot_types_and_bool_annotations(lib_types):
143-
types = lib_types.get_keyword_types('keyword_robot_types_and_bool_defaults')
144-
assert types == {'arg1': str, 'arg2': bool}
145-
133+
types = lib_types.get_keyword_types('keyword_robot_types_and_bool_hint')
134+
assert types == {'arg1': str}
146135

147-
def test_init_args(lib):
148-
types = lib.get_keyword_types('__init__')
149-
assert types == {'arg': bool}
136+
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
137+
def test_init_args(lib_types):
138+
types = lib_types.get_keyword_types('__init__')
139+
assert types == {'arg': str}
150140

151141

152142
def test_dummy_magic_method(lib):
@@ -180,7 +170,7 @@ def test_keyword_only_arguments(lib_types):
180170
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
181171
def test_keyword_only_arguments_many(lib_types):
182172
types = lib_types.get_keyword_types('keyword_only_arguments_many')
183-
assert types == {'other': type(None)}
173+
assert types == {}
184174

185175

186176
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
@@ -192,13 +182,13 @@ def test_keyword_mandatory_and_keyword_only_arguments(lib_types):
192182
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
193183
def test_keyword_only_arguments_many_positional_and_default(lib_types):
194184
types = lib_types.get_keyword_types('keyword_only_arguments_many_positional_and_default')
195-
assert types == {'four': bool, 'five': type(None), 'six': bool}
185+
assert types == {'four': Union[int, str], 'six': Union[bool, str]}
196186

197187

198188
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')
199189
def test_keyword_all_args(lib_types):
200190
types = lib_types.get_keyword_types('keyword_all_args')
201-
assert types == {'value': bool}
191+
assert types == {}
202192

203193

204194
@pytest.mark.skipif(PY2, reason='Only applicable on Python 3')

utest/test_robotlibcore.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def test_dir():
4141
'_DynamicCore__get_keyword_line',
4242
'_DynamicCore__get_keyword_path',
4343
'_DynamicCore__get_typing_hints',
44-
'_DynamicCore__join_defaults_with_types',
4544
'_HybridCore__get_members',
4645
'_HybridCore__get_members_from_instance',
4746
'_custom_name',
@@ -76,7 +75,6 @@ def test_dir():
7675
'_DynamicCore__get_keyword',
7776
'_DynamicCore__get_keyword_line',
7877
'_DynamicCore__get_keyword_path',
79-
'_DynamicCore__join_defaults_with_types',
8078
'get_keyword_arguments',
8179
'get_keyword_documentation',
8280
'get_keyword_source',

0 commit comments

Comments
 (0)