Skip to content

Commit 2208751

Browse files
gh-104050: Annotate Argument Clinic parameter permutation helpers (#106431)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 110b97c commit 2208751

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

Tools/clinic/clinic.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
import textwrap
2929
import traceback
3030

31-
from collections.abc import Callable
31+
from collections.abc import (
32+
Callable,
33+
Iterable,
34+
Iterator,
35+
Sequence,
36+
)
3237
from types import FunctionType, NoneType
3338
from typing import (
3439
Any,
@@ -516,7 +521,13 @@ class PythonLanguage(Language):
516521
checksum_line = "#/*[{dsl_name} end generated code: {arguments}]*/"
517522

518523

519-
def permute_left_option_groups(l):
524+
ParamGroup = Iterable["Parameter"]
525+
ParamTuple = tuple["Parameter", ...]
526+
527+
528+
def permute_left_option_groups(
529+
l: Sequence[ParamGroup]
530+
) -> Iterator[ParamTuple]:
520531
"""
521532
Given [(1,), (2,), (3,)], should yield:
522533
()
@@ -525,13 +536,15 @@ def permute_left_option_groups(l):
525536
(1, 2, 3)
526537
"""
527538
yield tuple()
528-
accumulator = []
539+
accumulator: list[Parameter] = []
529540
for group in reversed(l):
530541
accumulator = list(group) + accumulator
531542
yield tuple(accumulator)
532543

533544

534-
def permute_right_option_groups(l):
545+
def permute_right_option_groups(
546+
l: Sequence[ParamGroup]
547+
) -> Iterator[ParamTuple]:
535548
"""
536549
Given [(1,), (2,), (3,)], should yield:
537550
()
@@ -540,13 +553,17 @@ def permute_right_option_groups(l):
540553
(1, 2, 3)
541554
"""
542555
yield tuple()
543-
accumulator = []
556+
accumulator: list[Parameter] = []
544557
for group in l:
545558
accumulator.extend(group)
546559
yield tuple(accumulator)
547560

548561

549-
def permute_optional_groups(left, required, right):
562+
def permute_optional_groups(
563+
left: Sequence[ParamGroup],
564+
required: ParamGroup,
565+
right: Sequence[ParamGroup]
566+
) -> tuple[ParamTuple, ...]:
550567
"""
551568
Generator function that computes the set of acceptable
552569
argument lists for the provided iterables of
@@ -561,7 +578,7 @@ def permute_optional_groups(left, required, right):
561578
if left:
562579
raise ValueError("required is empty but left is not")
563580

564-
accumulator = []
581+
accumulator: list[ParamTuple] = []
565582
counts = set()
566583
for r in permute_right_option_groups(right):
567584
for l in permute_left_option_groups(left):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy