@@ -390,6 +390,10 @@ def test_cannot_be_called(self):
390
390
391
391
class TypeVarTupleTests (BaseTestCase ):
392
392
393
+ def assertEndsWith (self , string , tail ):
394
+ if not string .endswith (tail ):
395
+ self .fail (f"String { string !r} does not end with { tail !r} " )
396
+
393
397
def test_instance_is_equal_to_itself (self ):
394
398
Ts = TypeVarTuple ('Ts' )
395
399
self .assertEqual (Ts , Ts )
@@ -449,78 +453,51 @@ def test_variadic_class_repr_is_correct(self):
449
453
Ts = TypeVarTuple ('Ts' )
450
454
class A (Generic [Unpack [Ts ]]): pass
451
455
452
- self .assertTrue (repr (A [()]).endswith ('A[()]' ))
453
- self .assertTrue (repr (A [float ]).endswith ('A[float]' ))
454
- self .assertTrue (repr (A [float , str ]).endswith ('A[float, str]' ))
455
- self .assertTrue (repr (
456
- A [Unpack [tuple [int , ...]]]
457
- ).endswith (
458
- 'A[*tuple[int, ...]]'
459
- ))
460
- self .assertTrue (repr (
461
- A [float , Unpack [tuple [int , ...]]]
462
- ).endswith (
463
- 'A[float, *tuple[int, ...]]'
464
- ))
465
- self .assertTrue (repr (
466
- A [Unpack [tuple [int , ...]], str ]
467
- ).endswith (
468
- 'A[*tuple[int, ...], str]'
469
- ))
470
- self .assertTrue (repr (
471
- A [float , Unpack [tuple [int , ...]], str ]
472
- ).endswith (
473
- 'A[float, *tuple[int, ...], str]'
474
- ))
456
+ self .assertEndsWith (repr (A [()]), 'A[()]' )
457
+ self .assertEndsWith (repr (A [float ]), 'A[float]' )
458
+ self .assertEndsWith (repr (A [float , str ]), 'A[float, str]' )
459
+ self .assertEndsWith (repr (A [Unpack [tuple [int , ...]]]),
460
+ 'A[*tuple[int, ...]]' )
461
+ self .assertEndsWith (repr (A [float , Unpack [tuple [int , ...]]]),
462
+ 'A[float, *tuple[int, ...]]' )
463
+ self .assertEndsWith (repr (A [Unpack [tuple [int , ...]], str ]),
464
+ 'A[*tuple[int, ...], str]' )
465
+ self .assertEndsWith (repr (A [float , Unpack [tuple [int , ...]], str ]),
466
+ 'A[float, *tuple[int, ...], str]' )
475
467
476
468
def test_variadic_class_alias_repr_is_correct (self ):
477
469
Ts = TypeVarTuple ('Ts' )
478
470
class A (Generic [Unpack [Ts ]]): pass
479
471
480
472
B = A [Unpack [Ts ]]
481
- self .assertTrue (repr (B ).endswith ('A[*Ts]' ))
482
- with self .assertRaises (NotImplementedError ):
483
- B [()]
484
- with self .assertRaises (NotImplementedError ):
485
- B [float ]
486
- with self .assertRaises (NotImplementedError ):
487
- B [float , str ]
473
+ self .assertEndsWith (repr (B ), 'A[*Ts]' )
474
+ self .assertEndsWith (repr (B [()]), 'A[()]' )
475
+ self .assertEndsWith (repr (B [float ]), 'A[float]' )
476
+ self .assertEndsWith (repr (B [float , str ]), 'A[float, str]' )
488
477
489
478
C = A [Unpack [Ts ], int ]
490
- self .assertTrue (repr (C ).endswith ('A[*Ts, int]' ))
491
- with self .assertRaises (NotImplementedError ):
492
- C [()]
493
- with self .assertRaises (NotImplementedError ):
494
- C [float ]
495
- with self .assertRaises (NotImplementedError ):
496
- C [float , str ]
479
+ self .assertEndsWith (repr (C ), 'A[*Ts, int]' )
480
+ self .assertEndsWith (repr (C [()]), 'A[int]' )
481
+ self .assertEndsWith (repr (C [float ]), 'A[float, int]' )
482
+ self .assertEndsWith (repr (C [float , str ]), 'A[float, str, int]' )
497
483
498
484
D = A [int , Unpack [Ts ]]
499
- self .assertTrue (repr (D ).endswith ('A[int, *Ts]' ))
500
- with self .assertRaises (NotImplementedError ):
501
- D [()]
502
- with self .assertRaises (NotImplementedError ):
503
- D [float ]
504
- with self .assertRaises (NotImplementedError ):
505
- D [float , str ]
485
+ self .assertEndsWith (repr (D ), 'A[int, *Ts]' )
486
+ self .assertEndsWith (repr (D [()]), 'A[int]' )
487
+ self .assertEndsWith (repr (D [float ]), 'A[int, float]' )
488
+ self .assertEndsWith (repr (D [float , str ]), 'A[int, float, str]' )
506
489
507
490
E = A [int , Unpack [Ts ], str ]
508
- self .assertTrue (repr (E ).endswith ('A[int, *Ts, str]' ))
509
- with self .assertRaises (NotImplementedError ):
510
- E [()]
511
- with self .assertRaises (NotImplementedError ):
512
- E [float ]
513
- with self .assertRaises (NotImplementedError ):
514
- E [float , bool ]
491
+ self .assertEndsWith (repr (E ), 'A[int, *Ts, str]' )
492
+ self .assertEndsWith (repr (E [()]), 'A[int, str]' )
493
+ self .assertEndsWith (repr (E [float ]), 'A[int, float, str]' )
494
+ self .assertEndsWith (repr (E [float , str ]), 'A[int, float, str, str]' )
515
495
516
496
F = A [Unpack [Ts ], Unpack [tuple [str , ...]]]
517
- self .assertTrue (repr (F ).endswith ('A[*Ts, *tuple[str, ...]]' ))
518
- with self .assertRaises (NotImplementedError ):
519
- F [()]
520
- with self .assertRaises (NotImplementedError ):
521
- F [float ]
522
- with self .assertRaises (NotImplementedError ):
523
- F [float , int ]
497
+ self .assertEndsWith (repr (F ), 'A[*Ts, *tuple[str, ...]]' )
498
+ self .assertEndsWith (repr (F [()]), 'A[*tuple[str, ...]]' )
499
+ self .assertEndsWith (repr (F [float ]), 'A[float, *tuple[str, ...]]' )
500
+ self .assertEndsWith (repr (F [float , str ]), 'A[float, str, *tuple[str, ...]]' )
524
501
525
502
def test_cannot_subclass_class (self ):
526
503
with self .assertRaises (TypeError ):
0 commit comments