|
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) |
| 1 | +from makefun import with_signature, add_signature_parameters |
9 | 2 | 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 |
10 | 6 |
|
11 |
| -try: |
12 |
| - from inspect import Parameter |
| 7 | +try: # python 3.3+ |
| 8 | + from inspect import signature, Parameter |
13 | 9 | except ImportError:
|
14 |
| - from funcsigs import Parameter |
| 10 | + from funcsigs import signature, Parameter |
15 | 11 |
|
16 |
| -try: # Python 3.5+ |
17 |
| - from typing import Any, Callable, Optional |
| 12 | +try: # python 3.5+ |
| 13 | + from typing import Callable, Any, Optional |
18 | 14 | except ImportError:
|
19 | 15 | pass
|
20 | 16 |
|
21 |
| -try: # Python 3.9 |
22 |
| - from typing import Protocol, TypeVar, Union, overload |
23 |
| - try: # Python 3.10 |
24 |
| - from typing import ParamSpec |
25 |
| - except ImportError: |
26 |
| - from typing_extensions import ParamSpec |
27 | 17 |
|
28 |
| - P = ParamSpec("P") |
29 |
| - F = TypeVar("F", bound=Callable) |
30 |
| - |
31 |
| - class _Decorator(Protocol[P]): |
32 |
| - """ |
33 |
| - This is callable Protocol, to distinguish between cases where |
34 |
| - created decorator is called as `@decorator` or `@decorator()` |
35 |
| - """ |
36 |
| - |
37 |
| - @overload |
38 |
| - def __call__(self, func: F) -> F: |
39 |
| - # decorator is called without parenthesis: @decorator |
40 |
| - ... |
41 |
| - |
42 |
| - @overload |
43 |
| - def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Callable[[F], F]: |
44 |
| - # decorator is called with options or parenthesis: @decorator(some_option=...) |
45 |
| - ... |
46 |
| - |
47 |
| - @overload |
48 |
| - def function_decorator( |
49 |
| - enable_stack_introspection: Callable[P, Any], |
50 |
| - custom_disambiguator: Callable[[Any], FirstArgDisambiguation] = ..., |
51 |
| - flat_mode_decorated_name: Optional[str] = ..., |
52 |
| - ) -> _Decorator[P]: |
53 |
| - # @function_decorator is called without options or parenthesis |
54 |
| - ... |
55 |
| - |
56 |
| - @overload |
57 |
| - def function_decorator( |
58 |
| - enable_stack_introspection: bool = ..., |
59 |
| - custom_disambiguator: Callable[[Any], FirstArgDisambiguation] = ..., |
60 |
| - flat_mode_decorated_name: Optional[str] = ..., |
61 |
| - ) -> Callable[[Callable[P, Any]], _Decorator[P]]: |
62 |
| - # @function_decorator() is called with options or parenthesis. |
63 |
| - ... |
64 |
| -except ImportError: |
65 |
| - pass |
66 |
| - |
67 |
| - |
68 |
| -def function_decorator(enable_stack_introspection=False, # type: Union[Callable, bool] |
| 18 | +def function_decorator(enable_stack_introspection=False, # type: bool |
69 | 19 | custom_disambiguator=None, # type: Callable[[Any], FirstArgDisambiguation]
|
70 | 20 | flat_mode_decorated_name=None, # type: Optional[str]
|
71 | 21 | ):
|
|
0 commit comments