pincer.utils.conversion   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 36
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A remove_none() 0 24 5
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 __future__ import annotations
5
6
from typing import TYPE_CHECKING
7
8
if TYPE_CHECKING:
9
    from typing import Dict, List, Set, Union, Tuple
10
11
12
def remove_none(
0 ignored issues
show
Unused Code introduced by
Either all return statements in a function should return an expression, or none of them should.
Loading history...
13
    obj: Union[List, Dict, Set, Tuple]
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
14
) -> Union[List, Dict, Set, Tuple]:
15
    """
16
    Removes all ``None`` values from a list, dict or set.
17
18
    Parameters
19
    ----------
20
    obj : Union[List, Dict, Set, Tuple]
21
        The list, dict, set or tuple to remove ``None`` values from.
22
23
    Returns
24
    -------
25
    Union[List, Dict, Set, Tuple]
26
        The list, dict, set or tuple, without ``None`` values.
27
    """
28
    if isinstance(obj, list):
0 ignored issues
show
unused-code introduced by
Unnecessary "elif" after "return"
Loading history...
29
        return [i for i in obj if i is not None]
30
    elif isinstance(obj, tuple):
31
        return tuple(i for i in obj if i is not None)
32
    elif isinstance(obj, set):
33
        return obj - {None}
34
    elif isinstance(obj, dict):
35
        return {k: v for k, v in obj.items() if None not in (k, v)}
36