Passed
Push — master ( af9889...f446f0 )
by Max
01:14
created

structured_data._adt.ordering   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 24
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A _can_set_ordering() 0 3 2
A _ordering_options_are_valid() 0 5 3
A _set_ordering() 0 9 2
1
2
3
def _ordering_options_are_valid(
4
    *, eq: bool, order: bool  # pylint: disable=invalid-name
5
):
6
    if order and not eq:
7
        raise ValueError("eq must be true if order is true")
8
9
10
def _can_set_ordering(*, can_set: bool):
11
    if not can_set:
12
        raise ValueError("Can't add ordering methods if equality methods are provided.")
13
14
15
def _set_ordering(*, setter, cls: type, source: type):
16
    collision = setter(
17
        cls, source.__lt__, source.__le__, source.__gt__, source.__ge__  # type: ignore
18
    )
19
    if collision:
20
        raise TypeError(
21
            "Cannot overwrite attribute {collision} in class "
22
            "{name}. Consider using functools.total_ordering".format(
23
                collision=collision, name=cls.__name__
24
            )
25
        )
26