Total Complexity | 5 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Copyright Pincer 2021-Present |
||
|
|||
2 | # Full MIT License can be found in `LICENSE` at the project root. |
||
3 | |||
4 | from inspect import signature, isclass |
||
5 | from typing import Callable |
||
6 | |||
7 | from .insertion import should_pass_cls |
||
8 | |||
9 | |||
10 | def get_signature_and_params(func: Callable): |
||
11 | """Get the parameters and signature from a coroutine. |
||
12 | |||
13 | func: Callable |
||
14 | The coroutine from whom the information should be extracted. |
||
15 | |||
16 | Returns |
||
17 | ------- |
||
18 | Tuple[List[Union[:class:`str`, :class:`inspect.Parameter`]]] |
||
19 | Signature and list of parameters of the coroutine. |
||
20 | """ |
||
21 | if isclass(func): |
||
22 | func = getattr(func, "__init__") |
||
23 | |||
24 | if func is object.__init__: |
||
25 | return [], [] |
||
26 | |||
27 | sig = signature(func).parameters |
||
28 | params = list(sig) |
||
29 | |||
30 | if should_pass_cls(func): |
||
31 | del params[0] |
||
32 | |||
33 | return sig, params |
||
34 | |||
35 | |||
36 | def get_params(func: Callable): |
||
37 | """Get the parameters from a coroutine. |
||
38 | |||
39 | func: Callable |
||
40 | The coroutine from whom the information should be extracted. |
||
41 | |||
42 | Returns |
||
43 | ------- |
||
44 | List[Union[:class:`str`, :class:`inspect.Parameter`]] |
||
45 | List of parameters of the coroutine. |
||
46 | """ |
||
47 | return get_signature_and_params(func)[1] |
||
48 |