|
21 | 21 | import inspect |
22 | 22 | import os |
23 | 23 | from dataclasses import dataclass |
24 | | -from typing import Any, Callable, List, Optional, Union, get_type_hints |
| 24 | +from typing import Any, Callable, List, Optional, Union, get_type_hints, ForwardRef |
25 | 25 |
|
26 | 26 | from robot.api.deco import keyword # noqa: F401 |
27 | 27 | from robot.errors import DataError |
@@ -223,6 +223,17 @@ def _get_arguments(cls, function): |
223 | 223 | def _get_arg_spec(cls, function: Callable) -> inspect.FullArgSpec: |
224 | 224 | return inspect.getfullargspec(function) |
225 | 225 |
|
| 226 | + @classmethod |
| 227 | + def _get_type_hint(cls, function: Callable): |
| 228 | + try: |
| 229 | + hints = get_type_hints(function) |
| 230 | + except Exception: # noqa: BLE001 |
| 231 | + hints = function.__annotations__ |
| 232 | + for arg, hint in hints.items(): |
| 233 | + if isinstance(hint, ForwardRef): |
| 234 | + hint = hint.__forward_arg__ |
| 235 | + return hints |
| 236 | + |
226 | 237 | @classmethod |
227 | 238 | def _get_args(cls, arg_spec: inspect.FullArgSpec, function: Callable) -> list: |
228 | 239 | args = cls._drop_self_from_args(function, arg_spec) |
@@ -279,10 +290,7 @@ def _get_types(cls, function): |
279 | 290 | @classmethod |
280 | 291 | def _get_typing_hints(cls, function): |
281 | 292 | function = cls.unwrap(function) |
282 | | - try: |
283 | | - hints = get_type_hints(function) |
284 | | - except Exception: # noqa: BLE001 |
285 | | - hints = function.__annotations__ |
| 293 | + hints = cls._get_type_hint(function) |
286 | 294 | arg_spec = cls._get_arg_spec(function) |
287 | 295 | all_args = cls._args_as_list(function, arg_spec) |
288 | 296 | for arg_with_hint in list(hints): |
|
0 commit comments