Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
python-version: [3.6, 3.9, pypy3, 3.10.0-rc.1]
rf-version: [4.0.2, 4.1.1rc1]
rf-version: [4.0.2, 4.1.1]

steps:
- uses: actions/checkout@v2
Expand Down
32 changes: 0 additions & 32 deletions src/robotlibcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@
import os
import typing

from robot import __version__ as robot_version
from robot.utils import PY_VERSION


from robot.api.deco import keyword # noqa F401

RF32 = robot_version < '4.'

__version__ = '3.0.1.dev1'


Expand Down Expand Up @@ -244,9 +238,6 @@ def _get_typing_hints(cls, function):
# remove return and self statements
if arg_with_hint not in all_args:
hints.pop(arg_with_hint)
if RF32:
default = cls._get_defaults(arg_spec)
return cls._remove_optional_none_type_hints(hints, default)
return hints

@classmethod
Expand All @@ -260,29 +251,6 @@ def _args_as_list(cls, function, arg_spec):
function_args.append(arg_spec.varkw)
return function_args

# TODO: Remove when support RF 3.2 is dropped
# Copied from: robot.running.arguments.argumentparser
@classmethod
def _remove_optional_none_type_hints(cls, type_hints, defaults):
# If argument has None as a default, typing.get_type_hints adds
# optional None to the information it returns. We don't want that.
for arg, default in defaults:
if default is None and arg in type_hints:
type_ = type_hints[arg]
if cls._is_union(type_):
types = type_.__args__
if len(types) == 2 and types[1] is type(None): # noqa
type_hints[arg] = types[0]
return type_hints

# TODO: Remove when support RF 3.2 is dropped
# Copied from: robot.running.arguments.argumentparser
@classmethod
def _is_union(cls, typing_type):
if PY_VERSION >= (3, 7) and hasattr(typing_type, '__origin__'):
typing_type = typing_type.__origin__
return isinstance(typing_type, type(typing.Union))

@classmethod
def _get_defaults(cls, arg_spec):
if not arg_spec.defaults:
Expand Down
11 changes: 1 addition & 10 deletions utest/test_get_keyword_types.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
import typing

from robotlibcore import RF32

from typing import List, Union

from DynamicTypesAnnotationsLibrary import DynamicTypesAnnotationsLibrary
Expand Down Expand Up @@ -185,13 +183,6 @@ def test_keyword_with_decorator_arguments(lib_types):
assert types == {'arg1': bool, 'arg2': bool}


@pytest.mark.skipif(RF32, reason='Only for RF4+')
def test_keyword_optional_with_none_rf4(lib_types):
def test_keyword_optional_with_none(lib_types):
types = lib_types.get_keyword_types('keyword_optional_with_none')
assert types == {'arg': typing.Union[str, type(None)]}


@pytest.mark.skipif(not RF32, reason='Only for RF3.2+')
def test_keyword_optional_with_none_rf32(lib_types):
types = lib_types.get_keyword_types('keyword_optional_with_none')
assert types == {'arg': str}
11 changes: 2 additions & 9 deletions utest/test_keyword_builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import typing

from robotlibcore import KeywordBuilder, RF32
from robotlibcore import KeywordBuilder
from moc_library import MockLibrary
from DynamicTypesAnnotationsLibrary import DynamicTypesAnnotationsLibrary

Expand Down Expand Up @@ -78,14 +78,7 @@ def test_types(lib):
assert spec.argument_types == {'varargs': int, 'other': bool, 'kwargs': int}


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


@pytest.mark.skipif(RF32, reason='Only for RF4')
def test_optional_none_rf4(lib):
def test_optional_none(lib):
spec = KeywordBuilder.build(lib.optional_none)
assert spec.argument_types == {'arg1': typing.Union[str, None], 'arg2': typing.Union[str, None]}

Expand Down