mirror of
https://github.com/python/cpython.git
synced 2025-10-03 13:45:29 +00:00
gh-104050: Annotate Argument Clinic parameter permutation helpers (#106431)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
110b97c94c
commit
22087516bc
1 changed files with 24 additions and 7 deletions
|
@ -28,7 +28,12 @@ import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import (
|
||||||
|
Callable,
|
||||||
|
Iterable,
|
||||||
|
Iterator,
|
||||||
|
Sequence,
|
||||||
|
)
|
||||||
from types import FunctionType, NoneType
|
from types import FunctionType, NoneType
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
@ -516,7 +521,13 @@ class PythonLanguage(Language):
|
||||||
checksum_line = "#/*[{dsl_name} end generated code: {arguments}]*/"
|
checksum_line = "#/*[{dsl_name} end generated code: {arguments}]*/"
|
||||||
|
|
||||||
|
|
||||||
def permute_left_option_groups(l):
|
ParamGroup = Iterable["Parameter"]
|
||||||
|
ParamTuple = tuple["Parameter", ...]
|
||||||
|
|
||||||
|
|
||||||
|
def permute_left_option_groups(
|
||||||
|
l: Sequence[ParamGroup]
|
||||||
|
) -> Iterator[ParamTuple]:
|
||||||
"""
|
"""
|
||||||
Given [(1,), (2,), (3,)], should yield:
|
Given [(1,), (2,), (3,)], should yield:
|
||||||
()
|
()
|
||||||
|
@ -525,13 +536,15 @@ def permute_left_option_groups(l):
|
||||||
(1, 2, 3)
|
(1, 2, 3)
|
||||||
"""
|
"""
|
||||||
yield tuple()
|
yield tuple()
|
||||||
accumulator = []
|
accumulator: list[Parameter] = []
|
||||||
for group in reversed(l):
|
for group in reversed(l):
|
||||||
accumulator = list(group) + accumulator
|
accumulator = list(group) + accumulator
|
||||||
yield tuple(accumulator)
|
yield tuple(accumulator)
|
||||||
|
|
||||||
|
|
||||||
def permute_right_option_groups(l):
|
def permute_right_option_groups(
|
||||||
|
l: Sequence[ParamGroup]
|
||||||
|
) -> Iterator[ParamTuple]:
|
||||||
"""
|
"""
|
||||||
Given [(1,), (2,), (3,)], should yield:
|
Given [(1,), (2,), (3,)], should yield:
|
||||||
()
|
()
|
||||||
|
@ -540,13 +553,17 @@ def permute_right_option_groups(l):
|
||||||
(1, 2, 3)
|
(1, 2, 3)
|
||||||
"""
|
"""
|
||||||
yield tuple()
|
yield tuple()
|
||||||
accumulator = []
|
accumulator: list[Parameter] = []
|
||||||
for group in l:
|
for group in l:
|
||||||
accumulator.extend(group)
|
accumulator.extend(group)
|
||||||
yield tuple(accumulator)
|
yield tuple(accumulator)
|
||||||
|
|
||||||
|
|
||||||
def permute_optional_groups(left, required, right):
|
def permute_optional_groups(
|
||||||
|
left: Sequence[ParamGroup],
|
||||||
|
required: ParamGroup,
|
||||||
|
right: Sequence[ParamGroup]
|
||||||
|
) -> tuple[ParamTuple, ...]:
|
||||||
"""
|
"""
|
||||||
Generator function that computes the set of acceptable
|
Generator function that computes the set of acceptable
|
||||||
argument lists for the provided iterables of
|
argument lists for the provided iterables of
|
||||||
|
@ -561,7 +578,7 @@ def permute_optional_groups(left, required, right):
|
||||||
if left:
|
if left:
|
||||||
raise ValueError("required is empty but left is not")
|
raise ValueError("required is empty but left is not")
|
||||||
|
|
||||||
accumulator = []
|
accumulator: list[ParamTuple] = []
|
||||||
counts = set()
|
counts = set()
|
||||||
for r in permute_right_option_groups(right):
|
for r in permute_right_option_groups(right):
|
||||||
for l in permute_left_option_groups(left):
|
for l in permute_left_option_groups(left):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue