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

structured_data._adt.ordering._set_ordering()   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nop 4
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