structured_data._adt.ordering   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 14
dl 0
loc 26
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A ordering_options_are_valid() 0 6 3
A can_set_ordering() 0 5 2
A raise_for_collision() 0 5 2
1
"""Helpers for reasoning about ordering methods."""
2
3
import typing
4
5
6
def ordering_options_are_valid(
7
    *, eq: bool, order: bool  # pylint: disable=invalid-name
8
) -> None:
9
    """Check constraint: we can't define order if we didn't define equality."""
10
    if order and not eq:
11
        raise ValueError("eq must be true if order is true")
12
13
14
def can_set_ordering(*, can_set: bool) -> bool:
15
    """Reduce cyclomatic complexity of the ``__init_subclass__`` methods."""
16
    if not can_set:
17
        raise ValueError("Can't add ordering methods if equality methods are provided.")
18
    return True
19
20
21
def raise_for_collision(collision: typing.Union[bool, None, str], name: str) -> None:
22
    """Create an informational message about ordering method collisions."""
23
    if collision:
24
        raise TypeError(
25
            f"Cannot overwrite attribute {collision} in class "
26
            f"{name}. Consider using functools.total_ordering"
27
        )
28