raise_for_collision()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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