28
28
import textwrap
29
29
import traceback
30
30
31
- from collections .abc import Callable
31
+ from collections .abc import (
32
+ Callable ,
33
+ Iterable ,
34
+ Iterator ,
35
+ Sequence ,
36
+ )
32
37
from types import FunctionType , NoneType
33
38
from typing import (
34
39
Any ,
@@ -516,7 +521,13 @@ class PythonLanguage(Language):
516
521
checksum_line = "#/*[{dsl_name} end generated code: {arguments}]*/"
517
522
518
523
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 ]:
520
531
"""
521
532
Given [(1,), (2,), (3,)], should yield:
522
533
()
@@ -525,13 +536,15 @@ def permute_left_option_groups(l):
525
536
(1, 2, 3)
526
537
"""
527
538
yield tuple ()
528
- accumulator = []
539
+ accumulator : list [ Parameter ] = []
529
540
for group in reversed (l ):
530
541
accumulator = list (group ) + accumulator
531
542
yield tuple (accumulator )
532
543
533
544
534
- def permute_right_option_groups (l ):
545
+ def permute_right_option_groups (
546
+ l : Sequence [ParamGroup ]
547
+ ) -> Iterator [ParamTuple ]:
535
548
"""
536
549
Given [(1,), (2,), (3,)], should yield:
537
550
()
@@ -540,13 +553,17 @@ def permute_right_option_groups(l):
540
553
(1, 2, 3)
541
554
"""
542
555
yield tuple ()
543
- accumulator = []
556
+ accumulator : list [ Parameter ] = []
544
557
for group in l :
545
558
accumulator .extend (group )
546
559
yield tuple (accumulator )
547
560
548
561
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 , ...]:
550
567
"""
551
568
Generator function that computes the set of acceptable
552
569
argument lists for the provided iterables of
@@ -561,7 +578,7 @@ def permute_optional_groups(left, required, right):
561
578
if left :
562
579
raise ValueError ("required is empty but left is not" )
563
580
564
- accumulator = []
581
+ accumulator : list [ ParamTuple ] = []
565
582
counts = set ()
566
583
for r in permute_right_option_groups (right ):
567
584
for l in permute_left_option_groups (left ):
0 commit comments