@@ -406,8 +406,7 @@ class MyError(BaseException): pass
406
406
[out]
407
407
main:5: error: Exception must be derived from BaseException
408
408
409
- [case testRaiseClassobject]
410
- import typing
409
+ [case testRaiseClassObject]
411
410
class A: pass
412
411
class MyError(BaseException): pass
413
412
def f(): pass
@@ -418,6 +417,33 @@ raise object # E: Exception must be derived from BaseException
418
417
raise f # E: Exception must be derived from BaseException
419
418
[builtins fixtures/exception.pyi]
420
419
420
+ [case testRaiseClassObjectCustomInit]
421
+ class MyBaseError(BaseException):
422
+ def __init__(self, required) -> None:
423
+ ...
424
+ class MyError(Exception):
425
+ def __init__(self, required1, required2) -> None:
426
+ ...
427
+ class MyKwError(Exception):
428
+ def __init__(self, *, kwonly) -> None:
429
+ ...
430
+ class MyErrorWithDefault(Exception):
431
+ def __init__(self, optional=1) -> None:
432
+ ...
433
+ raise BaseException
434
+ raise Exception
435
+ raise BaseException(1)
436
+ raise Exception(2)
437
+ raise MyBaseError(4)
438
+ raise MyError(5, 6)
439
+ raise MyKwError(kwonly=7)
440
+ raise MyErrorWithDefault(8)
441
+ raise MyErrorWithDefault
442
+ raise MyBaseError # E: Too few arguments for "MyBaseError"
443
+ raise MyError # E: Too few arguments for "MyError"
444
+ raise MyKwError # E: Missing named argument "kwonly" for "MyKwError"
445
+ [builtins fixtures/exception.pyi]
446
+
421
447
[case testRaiseExceptionType]
422
448
import typing
423
449
x = None # type: typing.Type[BaseException]
0 commit comments