Skip to content

Commit d4e407d

Browse files
committed
Fix bug with RF 4.0 and working with types hints with Union
1 parent a389b22 commit d4e407d

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/robotlibcore.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import os
2323
import typing
2424

25-
from robot import version as robot_version
25+
from robot import __version__ as robot_version
2626
from robot.utils import PY_VERSION
2727

2828

@@ -262,6 +262,7 @@ def _args_as_list(cls, function, arg_spec):
262262
function_args.append(arg_spec.varkw)
263263
return function_args
264264

265+
# TODO: Remove when support RF 3.2 is dropped
265266
# Copied from: robot.running.arguments.argumentparser
266267
@classmethod
267268
def _remove_optional_none_type_hints(cls, type_hints, defaults):
@@ -276,6 +277,7 @@ def _remove_optional_none_type_hints(cls, type_hints, defaults):
276277
type_hints[arg] = types[0]
277278
return type_hints
278279

280+
# TODO: Remove when support RF 3.2 is dropped
279281
# Copied from: robot.running.arguments.argumentparser
280282
@classmethod
281283
def _is_union(cls, typing_type):

utest/test_get_keyword_types.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import sys
2-
from os.path import dirname, abspath, join
3-
41
import pytest
52
import typing
63

74
from robotlibcore import RF32
85

96
from typing import List, Union
107

11-
curdir = dirname(abspath(__file__))
12-
atest_dir = join(curdir, '..', 'atest')
13-
src = join(curdir, '..', 'src')
14-
sys.path.insert(0, src)
15-
sys.path.insert(0, atest_dir)
168
from DynamicTypesAnnotationsLibrary import DynamicTypesAnnotationsLibrary
179
from DynamicTypesAnnotationsLibrary import CustomObject
1810
from DynamicTypesLibrary import DynamicTypesLibrary
@@ -194,7 +186,7 @@ def test_keyword_with_decorator_arguments(lib_types):
194186

195187

196188
@pytest.mark.skipif(RF32, reason='Only for RF4+')
197-
def test_keyword_optional_with_none_rf32(lib_types):
189+
def test_keyword_optional_with_none_rf4(lib_types):
198190
lib = DynamicTypesAnnotationsLibrary("111")
199191
types = lib.get_keyword_types('keyword_optional_with_none')
200192
assert types == {'arg': typing.Union[str, type(None)]}

utest/test_keyword_builder.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
2+
import typing
23

3-
from robotlibcore import KeywordBuilder
4+
from robotlibcore import KeywordBuilder, RF32
45
from moc_library import MockLibrary
56
from DynamicTypesAnnotationsLibrary import DynamicTypesAnnotationsLibrary
67

@@ -77,11 +78,18 @@ def test_types(lib):
7778
assert spec.argument_types == {'varargs': int, 'other': bool, 'kwargs': int}
7879

7980

80-
def test_optional_none(lib):
81+
@pytest.mark.skipif(not RF32, reason='Only for RF3.2+')
82+
def test_optional_none_rf32(lib):
8183
spec = KeywordBuilder.build(lib.optional_none)
8284
assert spec.argument_types == {'arg1': str, 'arg2': str}
8385

8486

87+
@pytest.mark.skipif(RF32, reason='Only for RF4')
88+
def test_optional_none_rf4(lib):
89+
spec = KeywordBuilder.build(lib.optional_none)
90+
assert spec.argument_types == {'arg1': typing.Union[str, None], 'arg2': typing.Union[str, None]}
91+
92+
8593
def test_complex_deco(dyn_types):
8694
spec = KeywordBuilder.build(dyn_types.keyword_with_deco_and_signature)
8795
assert spec.argument_types == {'arg1': bool, 'arg2': bool}

0 commit comments

Comments
 (0)