@@ -382,25 +382,53 @@ def check(z, x, y):
382
382
check (complex (1.0 , 10.0 ), 1.0 , 10.0 )
383
383
check (complex (4.25 , 0.5 ), 4.25 , 0.5 )
384
384
385
- check (complex (4.25 + 0j , 0 ), 4.25 , 0.0 )
386
- check (complex (ComplexSubclass (4.25 + 0j ), 0 ), 4.25 , 0.0 )
387
- check (complex (WithComplex (4.25 + 0j ), 0 ), 4.25 , 0.0 )
388
- check (complex (4.25j , 0 ), 0.0 , 4.25 )
389
- check (complex (0j , 4.25 ), 0.0 , 4.25 )
390
- check (complex (0 , 4.25 + 0j ), 0.0 , 4.25 )
391
- check (complex (0 , ComplexSubclass (4.25 + 0j )), 0.0 , 4.25 )
385
+ with self .assertWarnsRegex (DeprecationWarning ,
386
+ "argument 'real' must be a real number, not complex" ):
387
+ check (complex (4.25 + 0j , 0 ), 4.25 , 0.0 )
388
+ with self .assertWarnsRegex (DeprecationWarning ,
389
+ "argument 'real' must be a real number, not .*ComplexSubclass" ):
390
+ check (complex (ComplexSubclass (4.25 + 0j ), 0 ), 4.25 , 0.0 )
391
+ with self .assertWarnsRegex (DeprecationWarning ,
392
+ "argument 'real' must be a real number, not .*WithComplex" ):
393
+ check (complex (WithComplex (4.25 + 0j ), 0 ), 4.25 , 0.0 )
394
+ with self .assertWarnsRegex (DeprecationWarning ,
395
+ "argument 'real' must be a real number, not complex" ):
396
+ check (complex (4.25j , 0 ), 0.0 , 4.25 )
397
+ with self .assertWarnsRegex (DeprecationWarning ,
398
+ "argument 'real' must be a real number, not complex" ):
399
+ check (complex (0j , 4.25 ), 0.0 , 4.25 )
400
+ with self .assertWarnsRegex (DeprecationWarning ,
401
+ "argument 'imag' must be a real number, not complex" ):
402
+ check (complex (0 , 4.25 + 0j ), 0.0 , 4.25 )
403
+ with self .assertWarnsRegex (DeprecationWarning ,
404
+ "argument 'imag' must be a real number, not .*ComplexSubclass" ):
405
+ check (complex (0 , ComplexSubclass (4.25 + 0j )), 0.0 , 4.25 )
392
406
with self .assertRaisesRegex (TypeError ,
393
- "second argument must be a number, not ' WithComplex' " ):
407
+ "argument 'imag' must be a real number, not .* WithComplex" ):
394
408
complex (0 , WithComplex (4.25 + 0j ))
395
- check (complex (0.0 , 4.25j ), - 4.25 , 0.0 )
396
- check (complex (4.25 + 0j , 0j ), 4.25 , 0.0 )
397
- check (complex (4.25j , 0j ), 0.0 , 4.25 )
398
- check (complex (0j , 4.25 + 0j ), 0.0 , 4.25 )
399
- check (complex (0j , 4.25j ), - 4.25 , 0.0 )
409
+ with self .assertWarnsRegex (DeprecationWarning ,
410
+ "argument 'imag' must be a real number, not complex" ):
411
+ check (complex (0.0 , 4.25j ), - 4.25 , 0.0 )
412
+ with self .assertWarnsRegex (DeprecationWarning ,
413
+ "argument 'real' must be a real number, not complex" ):
414
+ check (complex (4.25 + 0j , 0j ), 4.25 , 0.0 )
415
+ with self .assertWarnsRegex (DeprecationWarning ,
416
+ "argument 'real' must be a real number, not complex" ):
417
+ check (complex (4.25j , 0j ), 0.0 , 4.25 )
418
+ with self .assertWarnsRegex (DeprecationWarning ,
419
+ "argument 'real' must be a real number, not complex" ):
420
+ check (complex (0j , 4.25 + 0j ), 0.0 , 4.25 )
421
+ with self .assertWarnsRegex (DeprecationWarning ,
422
+ "argument 'real' must be a real number, not complex" ):
423
+ check (complex (0j , 4.25j ), - 4.25 , 0.0 )
400
424
401
425
check (complex (real = 4.25 ), 4.25 , 0.0 )
402
- check (complex (real = 4.25 + 0j ), 4.25 , 0.0 )
403
- check (complex (real = 4.25 + 1.5j ), 4.25 , 1.5 )
426
+ with self .assertWarnsRegex (DeprecationWarning ,
427
+ "argument 'real' must be a real number, not complex" ):
428
+ check (complex (real = 4.25 + 0j ), 4.25 , 0.0 )
429
+ with self .assertWarnsRegex (DeprecationWarning ,
430
+ "argument 'real' must be a real number, not complex" ):
431
+ check (complex (real = 4.25 + 1.5j ), 4.25 , 1.5 )
404
432
check (complex (imag = 1.5 ), 0.0 , 1.5 )
405
433
check (complex (real = 4.25 , imag = 1.5 ), 4.25 , 1.5 )
406
434
check (complex (4.25 , imag = 1.5 ), 4.25 , 1.5 )
@@ -420,22 +448,22 @@ def check(z, x, y):
420
448
del c , c2
421
449
422
450
self .assertRaisesRegex (TypeError ,
423
- "first argument must be a string or a number, not ' dict' " ,
451
+ "argument must be a string or a number, not dict" ,
424
452
complex , {})
425
453
self .assertRaisesRegex (TypeError ,
426
- "first argument must be a string or a number, not ' NoneType' " ,
454
+ "argument must be a string or a number, not NoneType" ,
427
455
complex , None )
428
456
self .assertRaisesRegex (TypeError ,
429
- "first argument must be a string or a number, not ' dict' " ,
457
+ "argument 'real' must be a real number, not dict" ,
430
458
complex , {1 :2 }, 0 )
431
459
self .assertRaisesRegex (TypeError ,
432
- "can't take second arg if first is a string " ,
460
+ "argument 'real' must be a real number, not str " ,
433
461
complex , '1' , 0 )
434
462
self .assertRaisesRegex (TypeError ,
435
- "second argument must be a number, not ' dict' " ,
463
+ "argument 'imag' must be a real number, not dict" ,
436
464
complex , 0 , {1 :2 })
437
465
self .assertRaisesRegex (TypeError ,
438
- "second arg can't be a string " ,
466
+ "argument 'imag' must be a real number, not str " ,
439
467
complex , 0 , '1' )
440
468
441
469
self .assertRaises (TypeError , complex , WithComplex (1.5 ))
0 commit comments