|
7 | 7 | import types |
8 | 8 | import typing |
9 | 9 | from pathlib import Path |
10 | | -from typing import Any, Callable, TypeAliasType |
11 | 10 |
|
12 | 11 | from loguru import logger |
13 | 12 |
|
|
22 | 21 | class ActionFailedException(Exception): ... |
23 | 22 |
|
24 | 23 |
|
25 | | -document_requester: Callable |
26 | | -document_saver: Callable |
| 24 | +document_requester: typing.Callable |
| 25 | +document_saver: typing.Callable |
27 | 26 | partial_result_sender: partial_result_sender_module.PartialResultSender |
28 | 27 |
|
29 | 28 |
|
30 | | -def set_partial_result_sender(send_func: Callable) -> None: |
| 29 | +def set_partial_result_sender(send_func: typing.Callable) -> None: |
31 | 30 | global partial_result_sender |
32 | 31 | partial_result_sender = partial_result_sender_module.PartialResultSender( |
33 | 32 | sender=send_func, wait_time_ms=300 |
@@ -85,13 +84,13 @@ async def update_config( |
85 | 84 |
|
86 | 85 |
|
87 | 86 | def resolve_func_args_with_di( |
88 | | - func: Callable, |
89 | | - known_args: dict[str, Callable[[Any], Any]] | None = None, |
| 87 | + func: typing.Callable, |
| 88 | + known_args: dict[str, typing.Callable[[typing.Any], typing.Any]] | None = None, |
90 | 89 | params_to_ignore: list[str] | None = None, |
91 | 90 | ): |
92 | 91 | func_parameters = inspect.signature(func).parameters |
93 | 92 | func_annotations = inspect.get_annotations(func, eval_str=True) |
94 | | - args: dict[str, Any] = {} |
| 93 | + args: dict[str, typing.Any] = {} |
95 | 94 | for param_name in func_parameters.keys(): |
96 | 95 | # default object constructor(__init__) has signature |
97 | 96 | # __init__(self, *args, **kwargs) |
@@ -121,7 +120,10 @@ def create_action_exec_info(action: domain.Action) -> domain.ActionExecInfo: |
121 | 120 | logger.error(f"Error importing action type: {e}") |
122 | 121 | raise e |
123 | 122 |
|
124 | | - if not isinstance(action_type_def, TypeAliasType): |
| 123 | + # typing.TypeAliasType is available in Python 3.12+ |
| 124 | + if hasattr(typing, "TypeAliasType") and not isinstance( |
| 125 | + action_type_def, typing.TypeAliasType |
| 126 | + ): |
125 | 127 | raise Exception("Action definition expected to be a type") |
126 | 128 |
|
127 | 129 | action_type_alias = action_type_def.__value__ |
@@ -447,7 +449,7 @@ async def run_action( |
447 | 449 | else: |
448 | 450 | action_result.update(handler_result) |
449 | 451 |
|
450 | | - serialized_result: dict[str, Any] | str | None = None |
| 452 | + serialized_result: dict[str, typing.Any] | str | None = None |
451 | 453 | result_format = "string" |
452 | 454 | run_return_code = code_action.RunReturnCode.SUCCESS |
453 | 455 | if isinstance(action_result, code_action.RunActionResult): |
|
0 commit comments