Skip to content

Commit 1517b79

Browse files
committed
Add pragma: no branch to Protocol stubs
Coverage branch tracking reports missing arcs on Protocol stub methods (def -> exit) because they are never called at runtime.
1 parent dc8d842 commit 1517b79

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/mcp/shared/_stream_protocols.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,35 @@
1515
T_contra = TypeVar("T_contra", contravariant=True)
1616

1717

18-
class ReadStream(Protocol[T_co]):
18+
# coverage branch tracking reports missing arcs on Protocol stub methods
19+
# (def -> exit) because they are never called at runtime.
20+
class ReadStream(Protocol[T_co]): # pragma: no branch
1921
"""Protocol for reading items from a stream.
2022
2123
Consumers that need the sender's context should use
2224
``getattr(stream, 'last_context', None)``.
2325
"""
2426

25-
async def receive(self) -> T_co: ...
26-
async def aclose(self) -> None: ...
27-
def __aiter__(self) -> ReadStream[T_co]: ...
28-
async def __anext__(self) -> T_co: ...
29-
async def __aenter__(self) -> Self: ...
30-
async def __aexit__(
27+
async def receive(self) -> T_co: ... # pragma: no branch
28+
async def aclose(self) -> None: ... # pragma: no branch
29+
def __aiter__(self) -> ReadStream[T_co]: ... # pragma: no branch
30+
async def __anext__(self) -> T_co: ... # pragma: no branch
31+
async def __aenter__(self) -> Self: ... # pragma: no branch
32+
async def __aexit__( # pragma: no branch
3133
self,
3234
exc_type: type[BaseException] | None,
3335
exc_val: BaseException | None,
3436
exc_tb: TracebackType | None,
3537
) -> bool | None: ...
3638

3739

38-
class WriteStream(Protocol[T_contra]):
40+
class WriteStream(Protocol[T_contra]): # pragma: no branch
3941
"""Protocol for writing items to a stream."""
4042

41-
async def send(self, item: T_contra, /) -> None: ...
42-
async def aclose(self) -> None: ...
43-
async def __aenter__(self) -> Self: ...
44-
async def __aexit__(
43+
async def send(self, item: T_contra, /) -> None: ... # pragma: no branch
44+
async def aclose(self) -> None: ... # pragma: no branch
45+
async def __aenter__(self) -> Self: ... # pragma: no branch
46+
async def __aexit__( # pragma: no branch
4547
self,
4648
exc_type: type[BaseException] | None,
4749
exc_val: BaseException | None,

0 commit comments

Comments
 (0)