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