Skip to content

Commit a74e557

Browse files
committed
Fix review suggestions
1 parent d6872e3 commit a74e557

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

changelog/13115.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Allows supplying ``ExceptionGroup[Exception]`` and ``BaseExceptionGroup[BaseException]`` to ``pytest.raises`` to keep full typing on ExcInfo.
2+
Parametrizing with other element types remains an error - we do not check the types of child exceptions and thus do not permit code that might look like we do.

src/_pytest/python_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,11 @@ def validate_exc(exc: type[E]) -> type[E]:
975975
origin_exc: type[E] | None = get_origin(exc)
976976
if origin_exc and issubclass(origin_exc, BaseExceptionGroup):
977977
exc_type = get_args(exc)[0]
978-
if issubclass(origin_exc, ExceptionGroup) and exc_type is Exception:
978+
if issubclass(origin_exc, ExceptionGroup) and exc_type in (Exception, Any):
979979
return cast(type[E], origin_exc)
980-
elif (
981-
issubclass(origin_exc, BaseExceptionGroup) and exc_type is BaseException
980+
elif issubclass(origin_exc, BaseExceptionGroup) and exc_type in (
981+
BaseException,
982+
Any,
982983
):
983984
return cast(type[E], origin_exc)
984985
else:

0 commit comments

Comments
 (0)