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

Function _determine_attrib_eq_order

src/attr/_make.py:1256–1296  ·  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

1254
1255
1256def _determine_attrib_eq_order(cmp, eq, order, default_eq):
1257 """
1258 Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
1259 values of eq and order. If *eq* is None, set it to *default_eq*.
1260 """
1261 if cmp is not None and any((eq is not None, order is not None)):
1262 msg = "Don't mix `cmp` with `eq' and `order`."
1263 raise ValueError(msg)
1264
1265 def decide_callable_or_boolean(value):
1266 """
1267 Decide whether a key function is used.
1268 """
1269 if callable(value):
1270 value, key = True, value
1271 else:
1272 key = None
1273 return value, key
1274
1275 # cmp takes precedence due to bw-compatibility.
1276 if cmp is not None:
1277 cmp, cmp_key = decide_callable_or_boolean(cmp)
1278 return cmp, cmp_key, cmp, cmp_key
1279
1280 # If left None, equality is set to the specified default and ordering
1281 # mirrors equality.
1282 if eq is None:
1283 eq, eq_key = default_eq, None
1284 else:
1285 eq, eq_key = decide_callable_or_boolean(eq)
1286
1287 if order is None:
1288 order, order_key = eq, eq_key
1289 else:
1290 order, order_key = decide_callable_or_boolean(order)
1291
1292 if eq is False and order is True:
1293 msg = "`order` can only be True if `eq` is True too."
1294 raise ValueError(msg)
1295
1296 return eq, eq_key, order, order_key
1297
1298
1299def _determine_whether_to_implement(

Callers 9

test_defaultMethod · 0.90
test_order_without_eqMethod · 0.90
test_mixMethod · 0.90
attribFunction · 0.85
__init__Method · 0.85

Calls 1