@@ -402,68 +402,8 @@ def __trunc__(self):
402
402
class JustTrunc (base ):
403
403
def __trunc__ (self ):
404
404
return 42
405
- with self .assertWarns (DeprecationWarning ):
406
- self .assertEqual (int (JustTrunc ()), 42 )
407
-
408
- class ExceptionalTrunc (base ):
409
- def __trunc__ (self ):
410
- 1 / 0
411
- with self .assertRaises (ZeroDivisionError ), \
412
- self .assertWarns (DeprecationWarning ):
413
- int (ExceptionalTrunc ())
414
-
415
- for trunc_result_base in (object , Classic ):
416
- class Index (trunc_result_base ):
417
- def __index__ (self ):
418
- return 42
419
-
420
- class TruncReturnsNonInt (base ):
421
- def __trunc__ (self ):
422
- return Index ()
423
- with self .assertWarns (DeprecationWarning ):
424
- self .assertEqual (int (TruncReturnsNonInt ()), 42 )
425
-
426
- class Intable (trunc_result_base ):
427
- def __int__ (self ):
428
- return 42
429
-
430
- class TruncReturnsNonIndex (base ):
431
- def __trunc__ (self ):
432
- return Intable ()
433
- with self .assertWarns (DeprecationWarning ):
434
- self .assertEqual (int (TruncReturnsNonInt ()), 42 )
435
-
436
- class NonIntegral (trunc_result_base ):
437
- def __trunc__ (self ):
438
- # Check that we avoid infinite recursion.
439
- return NonIntegral ()
440
-
441
- class TruncReturnsNonIntegral (base ):
442
- def __trunc__ (self ):
443
- return NonIntegral ()
444
- try :
445
- with self .assertWarns (DeprecationWarning ):
446
- int (TruncReturnsNonIntegral ())
447
- except TypeError as e :
448
- self .assertEqual (str (e ),
449
- "__trunc__ returned non-Integral"
450
- " (type NonIntegral)" )
451
- else :
452
- self .fail ("Failed to raise TypeError with %s" %
453
- ((base , trunc_result_base ),))
454
-
455
- # Regression test for bugs.python.org/issue16060.
456
- class BadInt (trunc_result_base ):
457
- def __int__ (self ):
458
- return 42.0
459
-
460
- class TruncReturnsBadInt (base ):
461
- def __trunc__ (self ):
462
- return BadInt ()
463
-
464
- with self .assertRaises (TypeError ), \
465
- self .assertWarns (DeprecationWarning ):
466
- int (TruncReturnsBadInt ())
405
+ with self .assertRaises (TypeError ):
406
+ int (JustTrunc ())
467
407
468
408
def test_int_subclass_with_index (self ):
469
409
class MyIndex (int ):
@@ -514,18 +454,6 @@ class BadInt2(int):
514
454
def __int__ (self ):
515
455
return True
516
456
517
- class TruncReturnsBadIndex :
518
- def __trunc__ (self ):
519
- return BadIndex ()
520
-
521
- class TruncReturnsBadInt :
522
- def __trunc__ (self ):
523
- return BadInt ()
524
-
525
- class TruncReturnsIntSubclass :
526
- def __trunc__ (self ):
527
- return True
528
-
529
457
bad_int = BadIndex ()
530
458
with self .assertWarns (DeprecationWarning ):
531
459
n = int (bad_int )
@@ -549,26 +477,6 @@ def __trunc__(self):
549
477
self .assertEqual (n , 1 )
550
478
self .assertIs (type (n ), int )
551
479
552
- bad_int = TruncReturnsBadIndex ()
553
- with self .assertWarns (DeprecationWarning ):
554
- n = int (bad_int )
555
- self .assertEqual (n , 1 )
556
- self .assertIs (type (n ), int )
557
-
558
- bad_int = TruncReturnsBadInt ()
559
- with self .assertWarns (DeprecationWarning ):
560
- self .assertRaises (TypeError , int , bad_int )
561
-
562
- good_int = TruncReturnsIntSubclass ()
563
- with self .assertWarns (DeprecationWarning ):
564
- n = int (good_int )
565
- self .assertEqual (n , 1 )
566
- self .assertIs (type (n ), int )
567
- with self .assertWarns (DeprecationWarning ):
568
- n = IntSubclass (good_int )
569
- self .assertEqual (n , 1 )
570
- self .assertIs (type (n ), IntSubclass )
571
-
572
480
def test_error_message (self ):
573
481
def check (s , base = None ):
574
482
with self .assertRaises (ValueError ,
0 commit comments