Skip to content

Commit

Permalink
Fix review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
tapetersen committed Jan 20, 2025
1 parent d6872e3 commit a74e557
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/13115.improvement.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Allows supplying ``ExceptionGroup[Exception]`` and ``BaseExceptionGroup[BaseException]`` to ``pytest.raises`` to keep full typing on ExcInfo.
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.
7 changes: 4 additions & 3 deletions src/_pytest/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,10 +975,11 @@ def validate_exc(exc: type[E]) -> type[E]:
origin_exc: type[E] | None = get_origin(exc)
if origin_exc and issubclass(origin_exc, BaseExceptionGroup):
exc_type = get_args(exc)[0]
if issubclass(origin_exc, ExceptionGroup) and exc_type is Exception:
if issubclass(origin_exc, ExceptionGroup) and exc_type in (Exception, Any):
return cast(type[E], origin_exc)
elif (
issubclass(origin_exc, BaseExceptionGroup) and exc_type is BaseException
elif issubclass(origin_exc, BaseExceptionGroup) and exc_type in (
BaseException,
Any,
):
return cast(type[E], origin_exc)
else:
Expand Down

0 comments on commit a74e557

Please sign in to comment.