Skip to content

Commit db0dab7

Browse files
g97iulio1609Copilot
andcommitted
fix: resolve pyright strict-mode errors in test_exception_utils
Add _get_exceptions() helper to provide typed access to BaseExceptionGroup.exceptions, avoiding reportUnknownMemberType errors. Use pyright: ignore[reportUnknownArgumentType] for the narrowed BaseExceptionGroup[Unknown] type after isinstance checks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ff7d4b6 commit db0dab7

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

tests/shared/test_exception_utils.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import asyncio
66
import sys
7+
from collections.abc import Sequence
78

89
import anyio
910
import pytest
@@ -14,6 +15,11 @@
1415
from exceptiongroup import BaseExceptionGroup
1516

1617

18+
def _get_exceptions(eg: BaseExceptionGroup[BaseException]) -> Sequence[BaseException]:
19+
"""Return the exceptions tuple with a known type for pyright."""
20+
return eg.exceptions
21+
22+
1723
# ---------------------------------------------------------------------------
1824
# collapse_exception_group() unit tests
1925
# ---------------------------------------------------------------------------
@@ -51,9 +57,10 @@ def test_multiple_real_errors(self) -> None:
5157
result = collapse_exception_group(eg)
5258
assert isinstance(result, BaseExceptionGroup)
5359
# Should contain only the two real errors
54-
assert len(result.exceptions) == 2
55-
assert e1 in result.exceptions
56-
assert e2 in result.exceptions
60+
excs = _get_exceptions(result) # pyright: ignore[reportUnknownArgumentType]
61+
assert len(excs) == 2
62+
assert e1 in excs
63+
assert e2 in excs
5764

5865
def test_single_real_error_no_cancelled(self) -> None:
5966
"""One real error, no Cancelled → unwrap to the real error."""
@@ -69,9 +76,10 @@ def test_multiple_real_errors_no_cancelled(self) -> None:
6976
eg = BaseExceptionGroup("task group", [e1, e2])
7077
result = collapse_exception_group(eg)
7178
assert isinstance(result, BaseExceptionGroup)
72-
assert len(result.exceptions) == 2
73-
assert e1 in result.exceptions
74-
assert e2 in result.exceptions
79+
excs = _get_exceptions(result) # pyright: ignore[reportUnknownArgumentType]
80+
assert len(excs) == 2
81+
assert e1 in excs
82+
assert e2 in excs
7583

7684

7785
# ---------------------------------------------------------------------------
@@ -108,7 +116,8 @@ async def test_multiple_failures_preserved(self) -> None:
108116

109117
# The group should contain both real errors
110118
eg = exc_info.value
111-
types = {type(e) for e in eg.exceptions}
119+
excs = _get_exceptions(eg) # pyright: ignore[reportUnknownArgumentType]
120+
types = {type(e) for e in excs}
112121
assert ValueError in types
113122
assert RuntimeError in types
114123

0 commit comments

Comments
 (0)