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