2828import textwrap
2929import traceback
3030
31- from collections .abc import Callable
31+ from collections .abc import (
32+ Callable ,
33+ Iterable ,
34+ Iterator ,
35+ Sequence ,
36+ )
3237from types import FunctionType , NoneType
3338from 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