| Total Complexity | 7 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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" |
||
| 28 |