@@ -530,12 +530,11 @@ class PythonLanguage(Language):
530
530
checksum_line = "#/*[{dsl_name} end generated code: {arguments}]*/"
531
531
532
532
533
- ParamGroup = Iterable ["Parameter" ]
534
533
ParamTuple = tuple ["Parameter" , ...]
535
534
536
535
537
536
def permute_left_option_groups (
538
- l : Sequence [ParamGroup ]
537
+ l : Sequence [Iterable [ Parameter ] ]
539
538
) -> Iterator [ParamTuple ]:
540
539
"""
541
540
Given [(1,), (2,), (3,)], should yield:
@@ -552,7 +551,7 @@ def permute_left_option_groups(
552
551
553
552
554
553
def permute_right_option_groups (
555
- l : Sequence [ParamGroup ]
554
+ l : Sequence [Iterable [ Parameter ] ]
556
555
) -> Iterator [ParamTuple ]:
557
556
"""
558
557
Given [(1,), (2,), (3,)], should yield:
@@ -569,9 +568,9 @@ def permute_right_option_groups(
569
568
570
569
571
570
def permute_optional_groups (
572
- left : Sequence [ParamGroup ],
573
- required : ParamGroup ,
574
- right : Sequence [ParamGroup ]
571
+ left : Sequence [Iterable [ Parameter ] ],
572
+ required : Iterable [ Parameter ] ,
573
+ right : Sequence [Iterable [ Parameter ] ]
575
574
) -> tuple [ParamTuple , ...]:
576
575
"""
577
576
Generator function that computes the set of acceptable
@@ -1374,7 +1373,11 @@ def group_to_variable_name(group: int) -> str:
1374
1373
adjective = "left_" if group < 0 else "right_"
1375
1374
return "group_" + adjective + str (abs (group ))
1376
1375
1377
- def render_option_group_parsing (self , f , template_dict ):
1376
+ def render_option_group_parsing (
1377
+ self ,
1378
+ f : Function ,
1379
+ template_dict : TemplateDict
1380
+ ) -> None :
1378
1381
# positional only, grouped, optional arguments!
1379
1382
# can be optional on the left or right.
1380
1383
# here's an example:
@@ -1398,11 +1401,11 @@ def render_option_group_parsing(self, f, template_dict):
1398
1401
if isinstance (parameters [0 ].converter , self_converter ):
1399
1402
del parameters [0 ]
1400
1403
1401
- group = None
1404
+ group : list [ Parameter ] | None = None
1402
1405
left = []
1403
1406
right = []
1404
- required = []
1405
- last = unspecified
1407
+ required : list [ Parameter ] = []
1408
+ last : int | Literal [ Sentinels . unspecified ] = unspecified
1406
1409
1407
1410
for p in parameters :
1408
1411
group_id = p .group
@@ -1415,6 +1418,7 @@ def render_option_group_parsing(self, f, template_dict):
1415
1418
group = required
1416
1419
else :
1417
1420
right .append (group )
1421
+ assert group is not None
1418
1422
group .append (p )
1419
1423
1420
1424
count_min = sys .maxsize
@@ -1433,19 +1437,21 @@ def render_option_group_parsing(self, f, template_dict):
1433
1437
continue
1434
1438
1435
1439
group_ids = {p .group for p in subset } # eliminate duplicates
1436
- d = {}
1440
+ d : dict [ str , str | int ] = {}
1437
1441
d ['count' ] = count
1438
1442
d ['name' ] = f .name
1439
1443
d ['format_units' ] = "" .join (p .converter .format_unit for p in subset )
1440
1444
1441
- parse_arguments = []
1445
+ parse_arguments : list [ str ] = []
1442
1446
for p in subset :
1443
1447
p .converter .parse_argument (parse_arguments )
1444
1448
d ['parse_arguments' ] = ", " .join (parse_arguments )
1445
1449
1446
1450
group_ids .discard (0 )
1447
- lines = [self .group_to_variable_name (g ) + " = 1;" for g in group_ids ]
1448
- lines = "\n " .join (lines )
1451
+ lines = "\n " .join ([
1452
+ self .group_to_variable_name (g ) + " = 1;"
1453
+ for g in group_ids
1454
+ ])
1449
1455
1450
1456
s = """\
1451
1457
case {count}:
0 commit comments