Passed
Pull Request — main (#114)
by
unknown
01:30
created

pincer.utils.signature.get_signature_and_params()   A

Complexity

Conditions 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 20
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
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