File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -452,7 +452,7 @@ def _parse_exc(
452
452
issubclass (origin_exc , BaseExceptionGroup )
453
453
and exc_type in (BaseException , Any )
454
454
):
455
- if not isinstance ( exc , Exception ):
455
+ if not issubclass ( origin_exc , ExceptionGroup ):
456
456
self .is_baseexception = True
457
457
return cast (type [BaseExcT_1 ], origin_exc )
458
458
else :
@@ -465,9 +465,9 @@ def _parse_exc(
465
465
)
466
466
# unclear if the Type/ValueError distinction is even helpful here
467
467
msg = f"expected exception must be { expected } , not "
468
- if isinstance (exc , type ):
468
+ if isinstance (exc , type ): # type: ignore[unreachable]
469
469
raise ValueError (msg + f"{ exc .__name__ !r} " )
470
- if isinstance (exc , BaseException ):
470
+ if isinstance (exc , BaseException ): # type: ignore[unreachable]
471
471
raise TypeError (msg + f"an exception instance ({ type (exc ).__name__ } )" )
472
472
raise TypeError (msg + repr (type (exc ).__name__ ))
473
473
Original file line number Diff line number Diff line change @@ -1325,6 +1325,16 @@ def test_annotated_group() -> None:
1325
1325
with RaisesExc (BaseExceptionGroup [BaseException ]):
1326
1326
raise BaseExceptionGroup ("" , [KeyboardInterrupt ()])
1327
1327
1328
+ # assure AbstractRaises.is_baseexception is set properly
1329
+ assert (
1330
+ RaisesGroup (ExceptionGroup [Exception ]).expected_type ()
1331
+ == "ExceptionGroup(ExceptionGroup)"
1332
+ )
1333
+ assert (
1334
+ RaisesGroup (BaseExceptionGroup [BaseException ]).expected_type ()
1335
+ == "BaseExceptionGroup(BaseExceptionGroup)"
1336
+ )
1337
+
1328
1338
1329
1339
def test_tuples () -> None :
1330
1340
# raises has historically supported one of several exceptions being raised
Original file line number Diff line number Diff line change @@ -417,7 +417,7 @@ def test_context() -> None:
417
417
with monkeypatch .context () as m :
418
418
m .setattr (functools , "partial" , 3 )
419
419
assert not inspect .isclass (functools .partial )
420
- assert inspect .isclass (functools .partial ) # type:ignore[unreachable]
420
+ assert inspect .isclass (functools .partial )
421
421
422
422
423
423
def test_context_classmethod () -> None :
You can’t perform that action at this time.
0 commit comments