Validate the combination of *cmp*, *eq*, and *order*. Derive the effective value of order.
(ctx: mypy.plugin.ClassDefContext)
| 239 | |
| 240 | |
| 241 | def _determine_eq_order(ctx: mypy.plugin.ClassDefContext) -> bool: |
| 242 | """ |
| 243 | Validate the combination of *cmp*, *eq*, and *order*. Derive the effective |
| 244 | value of order. |
| 245 | """ |
| 246 | cmp = _get_decorator_optional_bool_argument(ctx, "cmp") |
| 247 | eq = _get_decorator_optional_bool_argument(ctx, "eq") |
| 248 | order = _get_decorator_optional_bool_argument(ctx, "order") |
| 249 | |
| 250 | if cmp is not None and any((eq is not None, order is not None)): |
| 251 | ctx.api.fail('Don\'t mix "cmp" with "eq" and "order"', ctx.reason) |
| 252 | |
| 253 | # cmp takes precedence due to bw-compatibility. |
| 254 | if cmp is not None: |
| 255 | return cmp |
| 256 | |
| 257 | # If left None, equality is on and ordering mirrors equality. |
| 258 | if eq is None: |
| 259 | eq = True |
| 260 | |
| 261 | if order is None: |
| 262 | order = eq |
| 263 | |
| 264 | if eq is False and order is True: |
| 265 | ctx.api.fail("eq must be True if order is True", ctx.reason) |
| 266 | |
| 267 | return order |
| 268 | |
| 269 | |
| 270 | def _get_decorator_optional_bool_argument( |
no test coverage detected
searching dependent graphs…