pincer.utils.signature.get_signature_and_params()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 24
rs 9.9
c 0
b 0
f 0
cc 4
nop 1
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
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