@@ -462,10 +462,15 @@ class C(Generic[*Ts]): pass
462
462
('A[T]' , '[int]' , A [int ]),
463
463
('A[T]' , '[int, str]' , TypeError ),
464
464
('A[T]' , '[tuple[int, ...]]' , A [tuple [int , ...]]),
465
+ ('A[T]' , '[Tuple[int, ...]]' , A [Tuple [int , ...]]),
465
466
('A[T]' , '[*tuple[()]]' , A [* tuple [()]]), # Should raise TypeError?
467
+ ('A[T]' , '[*Tuple[()]]' , A [* Tuple [()]]), # Should raise TypeError?
466
468
('A[T]' , '[*tuple[int]]' , A [* tuple [int ]]), # Should be A[int]?
469
+ ('A[T]' , '[*Tuple[int]]' , A [* Tuple [int ]]), # Should be A[int]?
467
470
('A[T]' , '[*tuple[int, str]]' , A [* tuple [int , str ]]), # Should raise TypeError?
471
+ ('A[T]' , '[*Tuple[int, str]]' , A [* Tuple [int , str ]]), # Should raise TypeError?
468
472
('A[T]' , '[*tuple[int, ...]]' , A [* tuple [int , ...]]), # Should raise TypeError?
473
+ ('A[T]' , '[*Tuple[int, ...]]' , A [* Tuple [int , ...]]), # Should raise TypeError?
469
474
('A[T]' , '[*Ts]' , A [T ][* Ts ]), # Should raise TypeError?
470
475
('A[T]' , '[T, *Ts]' , TypeError ),
471
476
('A[T]' , '[*Ts, T]' , TypeError ),
@@ -475,35 +480,49 @@ class C(Generic[*Ts]): pass
475
480
('list[T]' , '[int]' , list [int ]),
476
481
('list[T]' , '[int, str]' , TypeError ),
477
482
('list[T]' , '[tuple[int, ...]]' , list [tuple [int , ...]]),
483
+ ('list[T]' , '[Tuple[int, ...]]' , list [Tuple [int , ...]]),
478
484
('list[T]' , '[*tuple[()]]' , list [* tuple [()]]), # Should be list[()]?
485
+ ('list[T]' , '[*Tuple[()]]' , list [* Tuple [()]]), # Should be list[()]?
479
486
('list[T]' , '[*tuple[int]]' , list [* tuple [int ]]), # Should be list[int]?
487
+ ('list[T]' , '[*Tuple[int]]' , list [* Tuple [int ]]), # Should be list[int]?
480
488
('list[T]' , '[*tuple[int, str]]' , list [* tuple [int , str ]]), # Should be list[int, str]?
489
+ ('list[T]' , '[*Tuple[int, str]]' , list [* Tuple [int , str ]]), # Should be list[int, str]?
481
490
# Why list[*tuple[int, ...]] rather than list[int, ...]?
482
491
# Because as of PEP 484, only tuple[int, ...] is explicitly
483
492
# given a meaning - list[int, ...] is not, and we might want
484
493
# to give a meaning other than "A list of ints of arbitrary
485
494
# length" in the future.
486
495
('list[T]' , '[*tuple[int, ...]]' , list [* tuple [int , ...]]),
496
+ ('list[T]' , '[*Tuple[int, ...]]' , list [* Tuple [int , ...]]),
487
497
# Ok, technically list isn't a variadic type, but we should
488
498
# allow this in line with our spirit of trying to be lenient
489
499
# about types at runtime.
490
500
('list[T]' , '[*Ts]' , list [* Ts ]),
491
501
('list[T]' , '[T, *Ts]' , TypeError ),
492
502
('list[T]' , '[*Ts, T]' , TypeError ),
493
503
('list[T, *tuple[int, ...]]' , '[int]' , list [int , * tuple [int , ...]]),
504
+ ('list[T, *Tuple[int, ...]]' , '[int]' , list [int , * Tuple [int , ...]]),
494
505
495
506
('B[T1, T2]' , '[()]' , TypeError ),
496
507
('B[T1, T2]' , '[int]' , TypeError ),
497
508
('B[T1, T2]' , '[int, str]' , B [int , str ]),
498
509
('B[T1, T2]' , '[int, str, bool]' , TypeError ),
499
510
('B[T1, T2]' , '[*tuple[int]]' , TypeError ),
511
+ ('B[T1, T2]' , '[*Tuple[int]]' , TypeError ),
500
512
('B[T1, T2]' , '[*tuple[int, str]]' , TypeError ), # Should be B[int, str]?
513
+ ('B[T1, T2]' , '[*Tuple[int, str]]' , TypeError ), # Should be B[int, str]?
501
514
('B[T1, T2]' , '[*tuple[int, str, bool]]' , TypeError ),
515
+ ('B[T1, T2]' , '[*Tuple[int, str, bool]]' , TypeError ),
502
516
('B[T1, T2]' , '[*tuple[int, str], *tuple[float, bool]]' , B [* tuple [int , str ], * tuple [float , bool ]]), # Should raise TypeError?
517
+ ('B[T1, T2]' , '[*Tuple[int, str], *Tuple[float, bool]]' , B [* Tuple [int , str ], * Tuple [float , bool ]]), # Should raise TypeError?
503
518
('B[T1, T2]' , '[tuple[int, ...]]' , TypeError ),
519
+ ('B[T1, T2]' , '[Tuple[int, ...]]' , TypeError ),
504
520
('B[T1, T2]' , '[tuple[int, ...], tuple[str, ...]]' , B [tuple [int , ...], tuple [str , ...]]),
521
+ ('B[T1, T2]' , '[Tuple[int, ...], Tuple[str, ...]]' , B [Tuple [int , ...], Tuple [str , ...]]),
505
522
('B[T1, T2]' , '[*tuple[int, ...]]' , TypeError ),
523
+ ('B[T1, T2]' , '[*Tuple[int, ...]]' , TypeError ),
506
524
('B[T1, T2]' , '[*tuple[int, ...], *tuple[str, ...]]' , B [* tuple [int , ...], * tuple [str , ...]]), # Should raise TypeError?
525
+ ('B[T1, T2]' , '[*Tuple[int, ...], *Tuple[str, ...]]' , B [* Tuple [int , ...], * Tuple [str , ...]]), # Should raise TypeError?
507
526
('B[T1, T2]' , '[*Ts]' , TypeError ),
508
527
('B[T1, T2]' , '[T, *Ts]' , B [T , * Ts ]), # Should raise TypeError?
509
528
('B[T1, T2]' , '[*Ts, T]' , B [* Ts , T ]), # Should raise TypeError?
@@ -515,32 +534,48 @@ class C(Generic[*Ts]): pass
515
534
('dict[T1, T2]' , '[int, str]' , dict [int , str ]),
516
535
('dict[T1, T2]' , '[int, str, bool]' , TypeError ),
517
536
('dict[T1, T2]' , '[*tuple[int]]' , TypeError ),
537
+ ('dict[T1, T2]' , '[*Tuple[int]]' , TypeError ),
518
538
('dict[T1, T2]' , '[*tuple[int, str]]' , TypeError ), # Should be dict[int, str]?
539
+ ('dict[T1, T2]' , '[*Tuple[int, str]]' , TypeError ), # Should be dict[int, str]?
519
540
('dict[T1, T2]' , '[*tuple[int, str, bool]]' , TypeError ),
541
+ ('dict[T1, T2]' , '[*Tuple[int, str, bool]]' , TypeError ),
520
542
('dict[T1, T2]' , '[*tuple[int, str], *tuple[float, bool]]' , dict [* tuple [int , str ], * tuple [float , bool ]]), # Should raise TypeError?
543
+ ('dict[T1, T2]' , '[*Tuple[int, str], *Tuple[float, bool]]' , dict [* Tuple [int , str ], * Tuple [float , bool ]]), # Should raise TypeError?
521
544
('dict[T1, T2]' , '[tuple[int, ...]]' , TypeError ),
545
+ ('dict[T1, T2]' , '[Tuple[int, ...]]' , TypeError ),
522
546
('dict[T1, T2]' , '[tuple[int, ...], tuple[str, ...]]' , dict [tuple [int , ...], tuple [str , ...]]),
547
+ ('dict[T1, T2]' , '[Tuple[int, ...], Tuple[str, ...]]' , dict [Tuple [int , ...], Tuple [str , ...]]),
523
548
# Should be dict[int, int]? This is a tricky one, because we might not
524
549
# have exactly two ints. But static checkers accept `t: tuple[int, ...]; t[1]`,
525
550
# so I think we should "Try to find to make it *work*" rather than
526
551
# "Try to find a way to make it *not* work".
527
552
('dict[T1, T2]' , '[*tuple[int, ...]]' , TypeError ),
553
+ ('dict[T1, T2]' , '[*Tuple[int, ...]]' , TypeError ),
528
554
('dict[T1, T2]' , '[*tuple[int, ...], *tuple[str, ...]]' , dict [* tuple [int , ...], * tuple [str , ...]]),
555
+ ('dict[T1, T2]' , '[*Tuple[int, ...], *Tuple[str, ...]]' , dict [* Tuple [int , ...], * Tuple [str , ...]]),
529
556
('dict[T1, T2]' , '[*Ts]' , TypeError ),
530
557
('dict[T1, T2]' , '[T, *Ts]' , dict [T , * Ts ]), # Should raise TypeError?
531
558
('dict[T1, T2]' , '[*Ts, T]' , dict [* Ts , T ]), # Should raise TypeError?
532
559
('dict[T1, *tuple[int, ...]]' , '[str]' , dict [str , * tuple [int , ...]]),
560
+ ('dict[T1, *Tuple[int, ...]]' , '[str]' , dict [str , * Tuple [int , ...]]),
533
561
('dict[T1, T2, *tuple[int, ...]]' , '[int, str]' , dict [int , str , * tuple [int , ...]]),
562
+ ('dict[T1, T2, *Tuple[int, ...]]' , '[int, str]' , dict [int , str , * Tuple [int , ...]]),
534
563
535
564
('C[*Ts]' , '[()]' , C [()]),
536
565
('C[*Ts]' , '[int]' , C [int ]),
537
566
('C[*Ts]' , '[int, str]' , C [int , str ]),
538
567
('C[*Ts]' , '[*tuple[int]]' , C [* tuple [int ]]), # Should be C[int]?
568
+ ('C[*Ts]' , '[*Tuple[int]]' , C [* Tuple [int ]]), # Should be C[int]?
539
569
('C[*Ts]' , '[*tuple[int, str]]' , C [* tuple [int , str ]]), # Should be C[int, str]?
570
+ ('C[*Ts]' , '[*Tuple[int, str]]' , C [* Tuple [int , str ]]), # Should be C[int, str]?
540
571
('C[*Ts]' , '[tuple[int, ...]]' , C [tuple [int , ...]]),
572
+ ('C[*Ts]' , '[Tuple[int, ...]]' , C [Tuple [int , ...]]),
541
573
('C[*Ts]' , '[tuple[int, ...], tuple[str, ...]]' , C [tuple [int , ...], tuple [str , ...]]),
574
+ ('C[*Ts]' , '[Tuple[int, ...], Tuple[str, ...]]' , C [Tuple [int , ...], Tuple [str , ...]]),
542
575
('C[*Ts]' , '[*tuple[int, ...]]' , C [* tuple [int , ...]]),
576
+ ('C[*Ts]' , '[*Tuple[int, ...]]' , C [* Tuple [int , ...]]),
543
577
('C[*Ts]' , '[*tuple[int, ...], *tuple[str, ...]]' , C [* tuple [int , ...], * tuple [str , ...]]),
578
+ ('C[*Ts]' , '[*Tuple[int, ...], *Tuple[str, ...]]' , C [* Tuple [int , ...], * Tuple [str , ...]]),
544
579
('C[*Ts]' , '[*Ts]' , C [* Ts ]),
545
580
('C[*Ts]' , '[T, *Ts]' , C [T , * Ts ]),
546
581
('C[*Ts]' , '[*Ts, T]' , C [* Ts , T ]),
@@ -551,19 +586,29 @@ class C(Generic[*Ts]): pass
551
586
('C[*Ts, T]' , '[int, str]' , C [int , str ]),
552
587
('C[*Ts, T]' , '[int, str, bool]' , C [int , str , bool ]),
553
588
('C[T, *Ts]' , '[*tuple[int, ...]]' , C [* tuple [int , ...]]), # Should be C[int, *tuple[int, ...]]?
589
+ ('C[T, *Ts]' , '[*Tuple[int, ...]]' , C [* Tuple [int , ...]]), # Should be C[int, *tuple[int, ...]]?
554
590
('C[T, *tuple[int, ...]]' , '[str]' , C [str , * tuple [int , ...]]),
591
+ ('C[T, *Tuple[int, ...]]' , '[str]' , C [str , * Tuple [int , ...]]),
555
592
('C[T1, T2, *tuple[int, ...]]' , '[str, bool]' , C [str , bool , * tuple [int , ...]]),
593
+ ('C[T1, T2, *Tuple[int, ...]]' , '[str, bool]' , C [str , bool , * Tuple [int , ...]]),
556
594
('C[T1, *tuple[int, ...], T2]' , '[str, bool]' , C [str , * tuple [int , ...], bool ]),
595
+ ('C[T1, *Tuple[int, ...], T2]' , '[str, bool]' , C [str , * Tuple [int , ...], bool ]),
557
596
558
597
('tuple[*Ts]' , '[()]' , TypeError ), # Should be tuple[()]?
559
598
('tuple[*Ts]' , '[int]' , tuple [(int ,),]), # Should be tuple[int]?
560
599
('tuple[*Ts]' , '[int, str]' , TypeError ), # Should be tuple[int, str]?
561
600
('tuple[*Ts]' , '[*tuple[int]]' , tuple [(* tuple [int ],),]), # Should be tuple[int]?
601
+ ('tuple[*Ts]' , '[*Tuple[int]]' , tuple [(* Tuple [int ],),]), # Should be tuple[int]?
562
602
('tuple[*Ts]' , '[*tuple[int, str]]' , tuple [(* tuple [int , str ],),]), # Should be tuple[int, str]?
603
+ ('tuple[*Ts]' , '[*Tuple[int, str]]' , tuple [(* Tuple [int , str ],),]), # Should be tuple[int, str]?
563
604
('tuple[*Ts]' , '[tuple[int, ...]]' , tuple [(tuple [int , ...],),]), # Should be tuple[tuple[int, ...]]?
605
+ ('tuple[*Ts]' , '[Tuple[int, ...]]' , tuple [(Tuple [int , ...],),]), # Should be tuple[tuple[int, ...]]?
564
606
('tuple[*Ts]' , '[tuple[int, ...], tuple[str, ...]]' , TypeError ), # Should be tuple[tuple[int, ...], tuple[str, ...]]?
607
+ ('tuple[*Ts]' , '[Tuple[int, ...], Tuple[str, ...]]' , TypeError ), # Should be tuple[tuple[int, ...], tuple[str, ...]]?
565
608
('tuple[*Ts]' , '[*tuple[int, ...]]' , tuple [(* tuple [int , ...],),]), # Should be tuple[int, ...]?
609
+ ('tuple[*Ts]' , '[*Tuple[int, ...]]' , tuple [(* Tuple [int , ...],),]), # Should be tuple[int, ...]?
566
610
('tuple[*Ts]' , '[*tuple[int, ...], *tuple[str, ...]]' , TypeError ), # Should be tuple[*tuple[int, ...], *tuple[str, ...]]?
611
+ ('tuple[*Ts]' , '[*Tuple[int, ...], *Tuple[str, ...]]' , TypeError ), # Should be tuple[*tuple[int, ...], *tuple[str, ...]]?
567
612
('tuple[*Ts]' , '[*Ts]' , tuple [(* Ts ,),]), # Should be tuple[*Ts]?
568
613
('tuple[*Ts]' , '[T, *Ts]' , TypeError ), # Should be tuple[T, *Ts]?
569
614
('tuple[*Ts]' , '[*Ts, T]' , TypeError ), # Should be tuple[*Ts, T]?
@@ -574,9 +619,13 @@ class C(Generic[*Ts]): pass
574
619
('tuple[*Ts, T]' , '[int, str]' , tuple [(int ,), str ]), # Should be tuple[int, str]?
575
620
('tuple[*Ts, T]' , '[int, str, bool]' , TypeError ), # Should be tuple[int, str, bool]?
576
621
('tuple[T, *Ts]' , '[*tuple[int, ...]]' , TypeError ), # Should be tuple[int, *tuple[int, ...]]?
622
+ ('tuple[T, *Ts]' , '[*Tuple[int, ...]]' , TypeError ), # Should be tuple[int, *tuple[int, ...]]?
577
623
('tuple[T, *tuple[int, ...]]' , '[str]' , tuple [str , * tuple [int , ...]]),
624
+ ('tuple[T, *Tuple[int, ...]]' , '[str]' , tuple [str , * Tuple [int , ...]]),
578
625
('tuple[T1, T2, *tuple[int, ...]]' , '[str, bool]' , tuple [str , bool , * tuple [int , ...]]),
626
+ ('tuple[T1, T2, *Tuple[int, ...]]' , '[str, bool]' , tuple [str , bool , * Tuple [int , ...]]),
579
627
('tuple[T1, *tuple[int, ...], T2]' , '[str, bool]' , tuple [str , * tuple [int , ...], bool ]),
628
+ ('tuple[T1, *Tuple[int, ...], T2]' , '[str, bool]' , tuple [str , * Tuple [int , ...], bool ]),
580
629
]
581
630
for alias , args , expected in tests :
582
631
with self .subTest (alias = alias , args = args , expected = expected ):
0 commit comments