@@ -385,6 +385,29 @@ def __complex__(self):
385
385
self .assertAlmostEqual (complex (complex1 (1j )), 2j )
386
386
self .assertRaises (TypeError , complex , complex2 (1j ))
387
387
388
+ @support .requires_IEEE_754
389
+ def test_constructor_special_numbers (self ):
390
+ class complex2 (complex ):
391
+ pass
392
+ for x in 0.0 , - 0.0 , INF , - INF , NAN :
393
+ for y in 0.0 , - 0.0 , INF , - INF , NAN :
394
+ with self .subTest (x = x , y = y ):
395
+ z = complex (x , y )
396
+ self .assertFloatsAreIdentical (z .real , x )
397
+ self .assertFloatsAreIdentical (z .imag , y )
398
+ z = complex2 (x , y )
399
+ self .assertIs (type (z ), complex2 )
400
+ self .assertFloatsAreIdentical (z .real , x )
401
+ self .assertFloatsAreIdentical (z .imag , y )
402
+ z = complex (complex2 (x , y ))
403
+ self .assertIs (type (z ), complex )
404
+ self .assertFloatsAreIdentical (z .real , x )
405
+ self .assertFloatsAreIdentical (z .imag , y )
406
+ z = complex2 (complex (x , y ))
407
+ self .assertIs (type (z ), complex2 )
408
+ self .assertFloatsAreIdentical (z .real , x )
409
+ self .assertFloatsAreIdentical (z .imag , y )
410
+
388
411
def test_hash (self ):
389
412
for x in range (- 30 , 30 ):
390
413
self .assertEqual (hash (x ), hash (complex (x , 0 )))
0 commit comments