@@ -409,11 +409,16 @@ main:5: error: Exception must be derived from BaseException
409
409
class A: pass
410
410
class MyError(BaseException): pass
411
411
def f(): pass
412
- raise BaseException
413
- raise MyError
414
- raise A # E: Exception must be derived from BaseException
415
- raise object # E: Exception must be derived from BaseException
416
- raise f # E: Exception must be derived from BaseException
412
+ if object():
413
+ raise BaseException
414
+ if object():
415
+ raise MyError
416
+ if object():
417
+ raise A # E: Exception must be derived from BaseException
418
+ if object():
419
+ raise object # E: Exception must be derived from BaseException
420
+ if object():
421
+ raise f # E: Exception must be derived from BaseException
417
422
[builtins fixtures/exception.pyi]
418
423
419
424
[case testRaiseClassObjectCustomInit]
@@ -429,18 +434,30 @@ class MyKwError(Exception):
429
434
class MyErrorWithDefault(Exception):
430
435
def __init__(self, optional=1) -> None:
431
436
...
432
- raise BaseException
433
- raise Exception
434
- raise BaseException(1)
435
- raise Exception(2)
436
- raise MyBaseError(4)
437
- raise MyError(5, 6)
438
- raise MyKwError(kwonly=7)
439
- raise MyErrorWithDefault(8)
440
- raise MyErrorWithDefault
441
- raise MyBaseError # E: Too few arguments for "MyBaseError"
442
- raise MyError # E: Too few arguments for "MyError"
443
- raise MyKwError # E: Missing named argument "kwonly" for "MyKwError"
437
+ if object():
438
+ raise BaseException
439
+ if object():
440
+ raise Exception
441
+ if object():
442
+ raise BaseException(1)
443
+ if object():
444
+ raise Exception(2)
445
+ if object():
446
+ raise MyBaseError(4)
447
+ if object():
448
+ raise MyError(5, 6)
449
+ if object():
450
+ raise MyKwError(kwonly=7)
451
+ if object():
452
+ raise MyErrorWithDefault(8)
453
+ if object():
454
+ raise MyErrorWithDefault
455
+ if object():
456
+ raise MyBaseError # E: Too few arguments for "MyBaseError"
457
+ if object():
458
+ raise MyError # E: Too few arguments for "MyError"
459
+ if object():
460
+ raise MyKwError # E: Missing named argument "kwonly" for "MyKwError"
444
461
[builtins fixtures/exception.pyi]
445
462
446
463
[case testRaiseExceptionType]
@@ -473,10 +490,14 @@ f: MyError
473
490
a: A
474
491
x: BaseException
475
492
del x
476
- raise e from a # E: Exception must be derived from BaseException
477
- raise e from e
478
- raise e from f
479
- raise e from x # E: Trying to read deleted variable "x"
493
+ if object():
494
+ raise e from a # E: Exception must be derived from BaseException
495
+ if object():
496
+ raise e from e
497
+ if object():
498
+ raise e from f
499
+ if object():
500
+ raise e from x # E: Trying to read deleted variable "x"
480
501
class A: pass
481
502
class MyError(BaseException): pass
482
503
[builtins fixtures/exception.pyi]
@@ -486,11 +507,16 @@ import typing
486
507
class A: pass
487
508
class MyError(BaseException): pass
488
509
def f(): pass
489
- raise BaseException from BaseException
490
- raise BaseException from MyError
491
- raise BaseException from A # E: Exception must be derived from BaseException
492
- raise BaseException from object # E: Exception must be derived from BaseException
493
- raise BaseException from f # E: Exception must be derived from BaseException
510
+ if object():
511
+ raise BaseException from BaseException
512
+ if object():
513
+ raise BaseException from MyError
514
+ if object():
515
+ raise BaseException from A # E: Exception must be derived from BaseException
516
+ if object():
517
+ raise BaseException from object # E: Exception must be derived from BaseException
518
+ if object():
519
+ raise BaseException from f # E: Exception must be derived from BaseException
494
520
[builtins fixtures/exception.pyi]
495
521
496
522
[case testTryFinallyStatement]
0 commit comments