|
1 |
| -from makefun import with_signature, add_signature_parameters |
| 1 | +from makefun import add_signature_parameters, with_signature |
| 2 | + |
| 3 | +from decopatch.utils_calls import (call_in_appropriate_mode, |
| 4 | + no_parenthesis_usage, |
| 5 | + with_parenthesis_usage) |
| 6 | +from decopatch.utils_disambiguation import ( |
| 7 | + DecoratorUsageInfo, FirstArgDisambiguation, can_arg_be_a_decorator_target, |
| 8 | + create_single_arg_callable_or_class_disambiguator, disambiguate_call) |
2 | 9 | from decopatch.utils_modes import SignatureInfo, make_decorator_spec
|
3 |
| -from decopatch.utils_disambiguation import create_single_arg_callable_or_class_disambiguator, disambiguate_call, \ |
4 |
| - DecoratorUsageInfo, can_arg_be_a_decorator_target |
5 |
| -from decopatch.utils_calls import with_parenthesis_usage, no_parenthesis_usage, call_in_appropriate_mode |
6 | 10 |
|
7 | 11 | try: # python 3.3+
|
8 |
| - from inspect import signature, Parameter |
| 12 | + from inspect import Parameter, signature |
9 | 13 | except ImportError:
|
10 |
| - from funcsigs import signature, Parameter |
| 14 | + from funcsigs import Parameter, signature |
11 | 15 |
|
12 | 16 | try: # python 3.5+
|
13 |
| - from typing import Callable, Any, Optional |
| 17 | + from typing import Any, Callable, Optional |
| 18 | +except ImportError: |
| 19 | + pass |
| 20 | + |
| 21 | +try: # Python 3.9 |
| 22 | + from typing import Any, Callable, Protocol, TypeVar, Union, overload |
| 23 | + try: # Python 3.10 |
| 24 | + from typing import ParamSpec |
| 25 | + except ImportError: |
| 26 | + from typing_extensions import ParamSpec |
| 27 | + |
| 28 | + P = ParamSpec("P") |
| 29 | + F = TypeVar("F", bound=Callable) |
| 30 | + |
| 31 | + class _Decorator(Protocol[P]): |
| 32 | + |
| 33 | + @overload |
| 34 | + def __call__(self, func: F) -> F: |
| 35 | + ... |
| 36 | + |
| 37 | + @overload |
| 38 | + def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Callable[[F], F]: |
| 39 | + ... |
| 40 | + |
| 41 | + @overload |
| 42 | + def function_decorator( |
| 43 | + enable_stack_introspection: Callable[P, Any], |
| 44 | + custom_disambiguator: Callable[[Any], FirstArgDisambiguation] = ..., |
| 45 | + flat_mode_decorated_name: Optional[str] = ..., |
| 46 | + ) -> _Decorator[P]: |
| 47 | + ... |
| 48 | + |
| 49 | + @overload |
| 50 | + def function_decorator( |
| 51 | + enable_stack_introspection: bool = ..., |
| 52 | + custom_disambiguator: Callable[[Any], FirstArgDisambiguation] = ..., |
| 53 | + flat_mode_decorated_name: Optional[str] = ..., |
| 54 | + ) -> Callable[[Callable[P, Any]], _Decorator[P]]: |
| 55 | + ... |
14 | 56 | except ImportError:
|
15 | 57 | pass
|
16 | 58 |
|
17 | 59 |
|
18 |
| -def function_decorator(enable_stack_introspection=False, # type: bool |
| 60 | +def function_decorator(enable_stack_introspection=False, # type: Union[Callable, bool] |
19 | 61 | custom_disambiguator=None, # type: Callable[[Any], FirstArgDisambiguation]
|
20 | 62 | flat_mode_decorated_name=None, # type: Optional[str]
|
21 | 63 | ):
|
|
0 commit comments