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

pincer.utils.extraction.get_signature_and_params()   A

Complexity

Conditions 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 2
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 typing import Any, Optional, Protocol, TypeVar
0 ignored issues
show
Bug introduced by
The name Protocol does not seem to exist in module typing.
Loading history...
5
6
T = TypeVar("T")
7
8
9
class GetItem(Protocol):
10
    """Represents a class which implements the __getitem__ property."""
11
12
    def __getitem__(self, key: int) -> Any:
13
        return ...
14
15
16
def get_index(
17
        collection: GetItem,
18
        index: int,
19
        fallback: Optional[T] = None
20
) -> Optional[T]:
21
    """
22
    Gets an item from a collection through index.
23
    Allows you to provide a fallback for if that index is out of bounds.
24
25
    :param collection:
26
        The collection from which the item is retrieved.
27
28
    :param index:
29
        The index of the item in the collection.
30
31
    :param fallback:
32
        The fallback value which will be used if the index doesn't
33
        exist. Default value is None.
34
35
    :return:
36
        The item at the provided index from the collection, or if that
37
        item doesn't exist it will return the fallback value.
38
    """
39
    try:
40
        return collection[index]
41
42
    except IndexError:
43
        return fallback
44