@@ -462,10 +462,15 @@ class C(Generic[*Ts]): pass
462462 ('A[T]' , '[int]' , A [int ]),
463463 ('A[T]' , '[int, str]' , TypeError ),
464464 ('A[T]' , '[tuple[int, ...]]' , A [tuple [int , ...]]),
465+ ('A[T]' , '[Tuple[int, ...]]' , A [Tuple [int , ...]]),
465466 ('A[T]' , '[*tuple[()]]' , A [* tuple [()]]), # Should raise TypeError?
467+ ('A[T]' , '[*Tuple[()]]' , A [* Tuple [()]]), # Should raise TypeError?
466468 ('A[T]' , '[*tuple[int]]' , A [* tuple [int ]]), # Should be A[int]?
469+ ('A[T]' , '[*Tuple[int]]' , A [* Tuple [int ]]), # Should be A[int]?
467470 ('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?
468472 ('A[T]' , '[*tuple[int, ...]]' , A [* tuple [int , ...]]), # Should raise TypeError?
473+ ('A[T]' , '[*Tuple[int, ...]]' , A [* Tuple [int , ...]]), # Should raise TypeError?
469474 ('A[T]' , '[*Ts]' , A [T ][* Ts ]), # Should raise TypeError?
470475 ('A[T]' , '[T, *Ts]' , TypeError ),
471476 ('A[T]' , '[*Ts, T]' , TypeError ),
@@ -475,35 +480,49 @@ class C(Generic[*Ts]): pass
475480 ('list[T]' , '[int]' , list [int ]),
476481 ('list[T]' , '[int, str]' , TypeError ),
477482 ('list[T]' , '[tuple[int, ...]]' , list [tuple [int , ...]]),
483+ ('list[T]' , '[Tuple[int, ...]]' , list [Tuple [int , ...]]),
478484 ('list[T]' , '[*tuple[()]]' , list [* tuple [()]]), # Should be list[()]?
485+ ('list[T]' , '[*Tuple[()]]' , list [* Tuple [()]]), # Should be list[()]?
479486 ('list[T]' , '[*tuple[int]]' , list [* tuple [int ]]), # Should be list[int]?
487+ ('list[T]' , '[*Tuple[int]]' , list [* Tuple [int ]]), # Should be list[int]?
480488 ('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]?
481490 # Why list[*tuple[int, ...]] rather than list[int, ...]?
482491 # Because as of PEP 484, only tuple[int, ...] is explicitly
483492 # given a meaning - list[int, ...] is not, and we might want
484493 # to give a meaning other than "A list of ints of arbitrary
485494 # length" in the future.
486495 ('list[T]' , '[*tuple[int, ...]]' , list [* tuple [int , ...]]),
496+ ('list[T]' , '[*Tuple[int, ...]]' , list [* Tuple [int , ...]]),
487497 # Ok, technically list isn't a variadic type, but we should
488498 # allow this in line with our spirit of trying to be lenient
489499 # about types at runtime.
490500 ('list[T]' , '[*Ts]' , list [* Ts ]),
491501 ('list[T]' , '[T, *Ts]' , TypeError ),
492502 ('list[T]' , '[*Ts, T]' , TypeError ),
493503 ('list[T, *tuple[int, ...]]' , '[int]' , list [int , * tuple [int , ...]]),
504+ ('list[T, *Tuple[int, ...]]' , '[int]' , list [int , * Tuple [int , ...]]),
494505
495506 ('B[T1, T2]' , '[()]' , TypeError ),
496507 ('B[T1, T2]' , '[int]' , TypeError ),
497508 ('B[T1, T2]' , '[int, str]' , B [int , str ]),
498509 ('B[T1, T2]' , '[int, str, bool]' , TypeError ),
499510 ('B[T1, T2]' , '[*tuple[int]]' , TypeError ),
511+ ('B[T1, T2]' , '[*Tuple[int]]' , TypeError ),
500512 ('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]?
501514 ('B[T1, T2]' , '[*tuple[int, str, bool]]' , TypeError ),
515+ ('B[T1, T2]' , '[*Tuple[int, str, bool]]' , TypeError ),
502516 ('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?
503518 ('B[T1, T2]' , '[tuple[int, ...]]' , TypeError ),
519+ ('B[T1, T2]' , '[Tuple[int, ...]]' , TypeError ),
504520 ('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 , ...]]),
505522 ('B[T1, T2]' , '[*tuple[int, ...]]' , TypeError ),
523+ ('B[T1, T2]' , '[*Tuple[int, ...]]' , TypeError ),
506524 ('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?
507526 ('B[T1, T2]' , '[*Ts]' , TypeError ),
508527 ('B[T1, T2]' , '[T, *Ts]' , B [T , * Ts ]), # Should raise TypeError?
509528 ('B[T1, T2]' , '[*Ts, T]' , B [* Ts , T ]), # Should raise TypeError?
@@ -515,32 +534,48 @@ class C(Generic[*Ts]): pass
515534 ('dict[T1, T2]' , '[int, str]' , dict [int , str ]),
516535 ('dict[T1, T2]' , '[int, str, bool]' , TypeError ),
517536 ('dict[T1, T2]' , '[*tuple[int]]' , TypeError ),
537+ ('dict[T1, T2]' , '[*Tuple[int]]' , TypeError ),
518538 ('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]?
519540 ('dict[T1, T2]' , '[*tuple[int, str, bool]]' , TypeError ),
541+ ('dict[T1, T2]' , '[*Tuple[int, str, bool]]' , TypeError ),
520542 ('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?
521544 ('dict[T1, T2]' , '[tuple[int, ...]]' , TypeError ),
545+ ('dict[T1, T2]' , '[Tuple[int, ...]]' , TypeError ),
522546 ('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 , ...]]),
523548 # Should be dict[int, int]? This is a tricky one, because we might not
524549 # have exactly two ints. But static checkers accept `t: tuple[int, ...]; t[1]`,
525550 # so I think we should "Try to find to make it *work*" rather than
526551 # "Try to find a way to make it *not* work".
527552 ('dict[T1, T2]' , '[*tuple[int, ...]]' , TypeError ),
553+ ('dict[T1, T2]' , '[*Tuple[int, ...]]' , TypeError ),
528554 ('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 , ...]]),
529556 ('dict[T1, T2]' , '[*Ts]' , TypeError ),
530557 ('dict[T1, T2]' , '[T, *Ts]' , dict [T , * Ts ]), # Should raise TypeError?
531558 ('dict[T1, T2]' , '[*Ts, T]' , dict [* Ts , T ]), # Should raise TypeError?
532559 ('dict[T1, *tuple[int, ...]]' , '[str]' , dict [str , * tuple [int , ...]]),
560+ ('dict[T1, *Tuple[int, ...]]' , '[str]' , dict [str , * Tuple [int , ...]]),
533561 ('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 , ...]]),
534563
535564 ('C[*Ts]' , '[()]' , C [()]),
536565 ('C[*Ts]' , '[int]' , C [int ]),
537566 ('C[*Ts]' , '[int, str]' , C [int , str ]),
538567 ('C[*Ts]' , '[*tuple[int]]' , C [* tuple [int ]]), # Should be C[int]?
568+ ('C[*Ts]' , '[*Tuple[int]]' , C [* Tuple [int ]]), # Should be C[int]?
539569 ('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]?
540571 ('C[*Ts]' , '[tuple[int, ...]]' , C [tuple [int , ...]]),
572+ ('C[*Ts]' , '[Tuple[int, ...]]' , C [Tuple [int , ...]]),
541573 ('C[*Ts]' , '[tuple[int, ...], tuple[str, ...]]' , C [tuple [int , ...], tuple [str , ...]]),
574+ ('C[*Ts]' , '[Tuple[int, ...], Tuple[str, ...]]' , C [Tuple [int , ...], Tuple [str , ...]]),
542575 ('C[*Ts]' , '[*tuple[int, ...]]' , C [* tuple [int , ...]]),
576+ ('C[*Ts]' , '[*Tuple[int, ...]]' , C [* Tuple [int , ...]]),
543577 ('C[*Ts]' , '[*tuple[int, ...], *tuple[str, ...]]' , C [* tuple [int , ...], * tuple [str , ...]]),
578+ ('C[*Ts]' , '[*Tuple[int, ...], *Tuple[str, ...]]' , C [* Tuple [int , ...], * Tuple [str , ...]]),
544579 ('C[*Ts]' , '[*Ts]' , C [* Ts ]),
545580 ('C[*Ts]' , '[T, *Ts]' , C [T , * Ts ]),
546581 ('C[*Ts]' , '[*Ts, T]' , C [* Ts , T ]),
@@ -551,19 +586,29 @@ class C(Generic[*Ts]): pass
551586 ('C[*Ts, T]' , '[int, str]' , C [int , str ]),
552587 ('C[*Ts, T]' , '[int, str, bool]' , C [int , str , bool ]),
553588 ('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, ...]]?
554590 ('C[T, *tuple[int, ...]]' , '[str]' , C [str , * tuple [int , ...]]),
591+ ('C[T, *Tuple[int, ...]]' , '[str]' , C [str , * Tuple [int , ...]]),
555592 ('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 , ...]]),
556594 ('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 ]),
557596
558597 ('tuple[*Ts]' , '[()]' , TypeError ), # Should be tuple[()]?
559598 ('tuple[*Ts]' , '[int]' , tuple [(int ,),]), # Should be tuple[int]?
560599 ('tuple[*Ts]' , '[int, str]' , TypeError ), # Should be tuple[int, str]?
561600 ('tuple[*Ts]' , '[*tuple[int]]' , tuple [(* tuple [int ],),]), # Should be tuple[int]?
601+ ('tuple[*Ts]' , '[*Tuple[int]]' , tuple [(* Tuple [int ],),]), # Should be tuple[int]?
562602 ('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]?
563604 ('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, ...]]?
564606 ('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, ...]]?
565608 ('tuple[*Ts]' , '[*tuple[int, ...]]' , tuple [(* tuple [int , ...],),]), # Should be tuple[int, ...]?
609+ ('tuple[*Ts]' , '[*Tuple[int, ...]]' , tuple [(* Tuple [int , ...],),]), # Should be tuple[int, ...]?
566610 ('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, ...]]?
567612 ('tuple[*Ts]' , '[*Ts]' , tuple [(* Ts ,),]), # Should be tuple[*Ts]?
568613 ('tuple[*Ts]' , '[T, *Ts]' , TypeError ), # Should be tuple[T, *Ts]?
569614 ('tuple[*Ts]' , '[*Ts, T]' , TypeError ), # Should be tuple[*Ts, T]?
@@ -574,9 +619,13 @@ class C(Generic[*Ts]): pass
574619 ('tuple[*Ts, T]' , '[int, str]' , tuple [(int ,), str ]), # Should be tuple[int, str]?
575620 ('tuple[*Ts, T]' , '[int, str, bool]' , TypeError ), # Should be tuple[int, str, bool]?
576621 ('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, ...]]?
577623 ('tuple[T, *tuple[int, ...]]' , '[str]' , tuple [str , * tuple [int , ...]]),
624+ ('tuple[T, *Tuple[int, ...]]' , '[str]' , tuple [str , * Tuple [int , ...]]),
578625 ('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 , ...]]),
579627 ('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 ]),
580629 ]
581630 for alias , args , expected in tests :
582631 with self .subTest (alias = alias , args = args , expected = expected ):
0 commit comments