MCPcopy Index your code
hub / github.com/python/mypy / _determine_eq_order

Function _determine_eq_order

mypy/plugins/attrs.py:241–267  ·  view source on GitHub ↗

Validate the combination of *cmp*, *eq*, and *order*. Derive the effective value of order.

(ctx: mypy.plugin.ClassDefContext)

Source from the content-addressed store, hash-verified

239
240
241def _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
270def _get_decorator_optional_bool_argument(

Callers 1

Calls 3

anyFunction · 0.85
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…