Issues (1445)

pincer/utils/conversion.py (4 issues)

1
# Copyright Pincer 2021-Present
0 ignored issues
show
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
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
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
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