MCPcopy
hub / github.com/python-attrs/attrs / _determine_attrs_eq_order

Function _determine_attrs_eq_order

src/attr/_make.py:1228–1253  ·  view source on GitHub ↗

Validate the combination of *cmp*, *eq*, and *order*. Derive the effective values of eq and order. If *eq* is None, set it to *default_eq*.

(cmp, eq, order, default_eq)

Source from the content-addressed store, hash-verified

1226
1227
1228def _determine_attrs_eq_order(cmp, eq, order, default_eq):
1229 """
1230 Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
1231 values of eq and order. If *eq* is None, set it to *default_eq*.
1232 """
1233 if cmp is not None and any((eq is not None, order is not None)):
1234 msg = "Don't mix `cmp` with `eq' and `order`."
1235 raise ValueError(msg)
1236
1237 # cmp takes precedence due to bw-compatibility.
1238 if cmp is not None:
1239 return cmp, cmp
1240
1241 # If left None, equality is set to the specified default and ordering
1242 # mirrors equality.
1243 if eq is None:
1244 eq = default_eq
1245
1246 if order is None:
1247 order = eq
1248
1249 if eq is False and order is True:
1250 msg = "`order` can only be True if `eq` is True too."
1251 raise ValueError(msg)
1252
1253 return eq, order
1254
1255
1256def _determine_attrib_eq_order(cmp, eq, order, default_eq):

Callers 6

test_defaultMethod · 0.90
test_order_without_eqMethod · 0.90
test_mixMethod · 0.90
attrsFunction · 0.85
make_classFunction · 0.85

Calls

no outgoing calls

Tested by 4

test_defaultMethod · 0.72
test_order_without_eqMethod · 0.72
test_mixMethod · 0.72