MCPcopy Create free account
hub / github.com/python/cpython / permute_optional_groups

Function permute_optional_groups

Tools/clinic/libclinic/function.py:303–333  ·  view source on GitHub ↗

Generator function that computes the set of acceptable argument lists for the provided iterables of argument groups. (Actually it generates a tuple of tuples.) Algorithm: prefer left options over right options. If required is empty, left must also be empty.

(
    left: Sequence[Iterable[Parameter]],
    required: Iterable[Parameter],
    right: Sequence[Iterable[Parameter]]
)

Source from the content-addressed store, hash-verified

301
302
303def permute_optional_groups(
304 left: Sequence[Iterable[Parameter]],
305 required: Iterable[Parameter],
306 right: Sequence[Iterable[Parameter]]
307) -> tuple[ParamTuple, ...]:
308 """
309 Generator function that computes the set of acceptable
310 argument lists for the provided iterables of
311 argument groups. (Actually it generates a tuple of tuples.)
312
313 Algorithm: prefer left options over right options.
314
315 If required is empty, left must also be empty.
316 """
317 required = tuple(required)
318 if not required:
319 if left:
320 raise ValueError("required is empty but left is not")
321
322 accumulator: list[ParamTuple] = []
323 counts = set()
324 for r in permute_right_option_groups(right):
325 for l in permute_left_option_groups(left):
326 t = l + required + r
327 if len(t) in counts:
328 continue
329 counts.add(len(t))
330 accumulator.append(t)
331
332 accumulator.sort(key=len)
333 return tuple(accumulator)

Callers 4

_testMethod · 0.90
fnMethod · 0.90

Calls 6

setFunction · 0.85
addMethod · 0.45
appendMethod · 0.45
sortMethod · 0.45

Tested by 3

_testMethod · 0.72
fnMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…