From ddfafb3d5dc342aef37651ca133aa8380fc53594 Mon Sep 17 00:00:00 2001 From: jasinluo Date: Fri, 30 Oct 2026 10:59:22 +0800 Subject: [PATCH] refactor(stream): move the client transport Stream into the stream package ClientStream is the only caller. Drop the old client exports so importing the client no longer pulls in the stream package. --- trpc_sdk/client/__init__.py | 6 ------ trpc_sdk/stream/__init__.py | 6 ++++++ trpc_sdk/stream/_client.py | 2 +- trpc_sdk/{client => stream}/_stream.py | 8 ++++---- trpc_sdk/{client => stream}/_stream_factory.py | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) rename trpc_sdk/{client => stream}/_stream.py (96%) rename trpc_sdk/{client => stream}/_stream_factory.py (92%) diff --git a/trpc_sdk/client/__init__.py b/trpc_sdk/client/__init__.py index f3ecf9d..8d831f1 100644 --- a/trpc_sdk/client/__init__.py +++ b/trpc_sdk/client/__init__.py @@ -13,8 +13,6 @@ - :mod:`~trpc_sdk.client._options` — ``Options`` container and per-request construction - :mod:`~trpc_sdk.client._client` — unary invoke path: message, node select, timeout -- :mod:`~trpc_sdk.client._stream` — client-side stream implementations -- :mod:`~trpc_sdk.client._stream_factory` — stream factories; each call needs a fresh stream - :mod:`~trpc_sdk.client._config` — deprecated shim over :class:`trpc_sdk.config.TrpcConfig` """ @@ -28,14 +26,10 @@ from ._client import select_node from ._client import set_timeout from ._client import update_message -from ._stream import Stream -from ._stream_factory import create_stream __all__ = [ "Client", "Options", - "Stream", - "create_stream", "get_client", "get_options", "normalize_options", diff --git a/trpc_sdk/stream/__init__.py b/trpc_sdk/stream/__init__.py index eafb4ab..4b852da 100644 --- a/trpc_sdk/stream/__init__.py +++ b/trpc_sdk/stream/__init__.py @@ -12,6 +12,8 @@ The package is split by responsibility: - :mod:`~trpc_sdk.stream._client` — :class:`ClientStream` and the client factory +- :mod:`~trpc_sdk.stream._stream` — transport connection used by :class:`ClientStream` +- :mod:`~trpc_sdk.stream._stream_factory` — one fresh :class:`Stream` per call - :mod:`~trpc_sdk.stream._server` — :class:`ServerStream` and :class:`StreamDispatcher` - :mod:`~trpc_sdk.stream._flow_control` — send / receive window - :mod:`~trpc_sdk.stream._constants`, :mod:`~trpc_sdk.stream._options`, @@ -36,6 +38,8 @@ from ._server import StreamDispatcher from ._server import create_server_stream from ._server import create_stream_dispatcher +from ._stream import Stream +from ._stream_factory import create_stream from ._types import ClientStreamDesc __all__ = [ @@ -52,6 +56,8 @@ "ClientStream", "ClientStreamDesc", "Client", + "Stream", + "create_stream", "create_stream_client", "default_stream_client", # Server diff --git a/trpc_sdk/stream/_client.py b/trpc_sdk/stream/_client.py index 72be9db..4b14d46 100644 --- a/trpc_sdk/stream/_client.py +++ b/trpc_sdk/stream/_client.py @@ -28,7 +28,6 @@ from trpc_sdk.abc import clone_context_and_message from trpc_sdk.abc import create_frame_head from trpc_sdk.client import Options -from trpc_sdk.client import create_stream from trpc_sdk.client import get_options from trpc_sdk.client import update_message from trpc_sdk.common import get_or_create_event_loop @@ -45,6 +44,7 @@ from ._flow_control import ReceiveControl from ._flow_control import SendControl from ._options import get_window_size +from ._stream_factory import create_stream from ._types import ClientStreamDesc diff --git a/trpc_sdk/client/_stream.py b/trpc_sdk/stream/_stream.py similarity index 96% rename from trpc_sdk/client/_stream.py rename to trpc_sdk/stream/_stream.py index ecc7476..5e72c68 100644 --- a/trpc_sdk/client/_stream.py +++ b/trpc_sdk/stream/_stream.py @@ -8,7 +8,7 @@ ``Stream`` is the public ``trpc_sdk.stream`` protocol transport. -Build instances through :func:`trpc_sdk.client.create_stream`. ``opts`` stays +Build instances through :func:`trpc_sdk.stream.create_stream`. ``opts`` stays ``None`` until :meth:`Stream.start` injects the per-call transport, codec and deadline. """ @@ -19,12 +19,12 @@ from trpc_sdk.abc import BaseClientStreamConnection from trpc_sdk.abc import TrpcContext +from trpc_sdk.client import Options +from trpc_sdk.client import select_node +from trpc_sdk.client import set_timeout from trpc_sdk.compressor import compress from trpc_sdk.serialization import serialize from trpc_sdk.utils import now_ms -from ._client import select_node -from ._client import set_timeout -from ._options import Options class Stream(BaseClientStreamConnection): diff --git a/trpc_sdk/client/_stream_factory.py b/trpc_sdk/stream/_stream_factory.py similarity index 92% rename from trpc_sdk/client/_stream_factory.py rename to trpc_sdk/stream/_stream_factory.py index df7c476..5075b51 100644 --- a/trpc_sdk/client/_stream_factory.py +++ b/trpc_sdk/stream/_stream_factory.py @@ -7,7 +7,7 @@ """Client stream factories. Each outbound stream call needs a fresh object: :attr:`Stream.opts` stays -``None`` until :meth:`~trpc_sdk.client.Stream.start` fills in the per-call +``None`` until :meth:`~trpc_sdk.stream.Stream.start` fills in the per-call transport, codec and deadline. A shared instance would leak one call's options into the next. """