Skip to content

Commit 9ae3455

Browse files
Update docstrings for consistency in rendered API (#173)
Signed-off-by: Stefan VanBuren <svanburen@buf.build>
1 parent 9cb72bd commit 9ae3455

14 files changed

Lines changed: 45 additions & 48 deletions

src/connectrpc/_client_async.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,16 @@ def __init__(
105105
106106
Args:
107107
address: The address of the server to connect to, including scheme.
108-
proto_json: Whether to use JSON for the protocol
108+
proto_json: Whether to use JSON for the protocol.
109+
protocol: The [ProtocolType][] to use for requests.
109110
accept_compression: Compression algorithms to accept from the server. If unset,
110111
defaults to gzip. If set to empty, disables response compression.
111112
send_compression: Compression algorithm to use for sending requests. If unset,
112113
defaults to gzip. If set to None, disables request compression.
113-
timeout_ms: The timeout for requests in milliseconds
114-
read_max_bytes: The maximum number of bytes to read from the response
115-
interceptors: A list of interceptors to apply to requests
116-
http_client: A pyqwest Client to use for requests
114+
timeout_ms: The timeout for requests in milliseconds.
115+
read_max_bytes: The maximum number of bytes to read from the response.
116+
interceptors: A list of interceptors to apply to requests.
117+
http_client: A pyqwest Client to use for requests.
117118
"""
118119
self._address = address
119120
self._codec = get_proto_json_codec() if proto_json else get_proto_binary_codec()

src/connectrpc/_client_sync.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,16 @@ def __init__(
9595
9696
Args:
9797
address: The address of the server to connect to, including scheme.
98-
proto_json: Whether to use JSON for the protocol
98+
proto_json: Whether to use JSON for the protocol.
99+
protocol: The [ProtocolType][] to use for requests.
99100
accept_compression: Compression algorithms to accept from the server. If unset,
100101
defaults to gzip. If set to empty, disables response compression.
101102
send_compression: Compression algorithm to use for sending requests. If unset,
102103
defaults to gzip. If set to None, disables request compression.
103-
timeout_ms: The timeout for requests in milliseconds
104-
read_max_bytes: The maximum number of bytes to read from the response
105-
interceptors: A list of interceptors to apply to requests
106-
http_client: A pyqwest SyncClient to use for requests
104+
timeout_ms: The timeout for requests in milliseconds.
105+
read_max_bytes: The maximum number of bytes to read from the response.
106+
interceptors: A list of interceptors to apply to requests.
107+
http_client: A pyqwest SyncClient to use for requests.
107108
"""
108109
self._address = address
109110
self._codec = get_proto_json_codec() if proto_json else get_proto_binary_codec()

src/connectrpc/_compression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def decompress(self, data: bytes | bytearray | memoryview) -> bytes:
2626
_identity = IdentityCompression()
2727

2828
_gzip = GzipCompression()
29-
_default_compressions = {"gzip": _gzip, "identity": _identity}
29+
_default_compressions: dict[str, Compression] = {"gzip": _gzip, "identity": _identity}
3030

3131

3232
def resolve_compressions(

src/connectrpc/_interceptor_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ class MetadataInterceptor(Protocol[T]):
126126
access to metadata such as headers and trailers.
127127
128128
To access request and response bodies of a method, instead use an interceptor
129-
corresponding to the type of method such as UnaryInterceptor.
129+
corresponding to the type of method such as [UnaryInterceptor][].
130130
"""
131131

132132
async def on_start(self, ctx: RequestContext) -> T:
133-
"""Called when the RPC starts. The return value will be passed to on_end as-is.
133+
"""Called when the RPC starts. The return value will be passed to [on_end][] as-is.
134134
For example, if measuring RPC invocation time, on_start may return the current
135-
time. If a return value isn't needed or on_end won't be used, return None.
135+
time. If a return value isn't needed or [on_end][] won't be used, return None.
136136
"""
137137
...
138138

src/connectrpc/_interceptor_sync.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ class MetadataInterceptorSync(Protocol[T]):
126126
access to metadata such as headers and trailers.
127127
128128
To access request and response bodies of a method, instead use an interceptor
129-
corresponding to the type of method such as UnaryInterceptorSync.
129+
corresponding to the type of method such as [UnaryInterceptorSync][].
130130
"""
131131

132132
def on_start_sync(self, ctx: RequestContext) -> T:
133-
"""Called when the RPC starts. The return value will be passed to on_end as-is.
134-
For example, if measuring RPC invocation time, on_start may return the current
135-
time. If a return value isn't needed or on_end won't be used, return None.
133+
"""Called when the RPC starts. The return value will be passed to [on_end_sync][] as-is.
134+
For example, if measuring RPC invocation time, on_start_sync may return the current
135+
time. If a return value isn't needed or [on_end_sync][] won't be used, return None.
136136
"""
137137
...
138138

src/connectrpc/_server_async.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ def __init__(
9595
9696
Args:
9797
service: The service instance or async generator that yields the service during lifespan.
98-
endpoints: A mapping of URL paths to endpoints resolved from service.
98+
endpoints: A callable that takes the service instance and returns a mapping of URL
99+
paths to endpoints. Typically provided directly by generated code from the
100+
Connect Python plugin.
99101
interceptors: A sequence of interceptors to apply to the endpoints.
100102
read_max_bytes: Maximum size of request messages.
101103
compressions: Supported compression algorithms. If unset, defaults to gzip.

src/connectrpc/_server_shared.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Endpoint(Generic[REQ, RES]):
2121
Represents an endpoint in a service.
2222
2323
Attributes:
24-
method: The method to map the the RPC function.
24+
method: The method to map to the RPC function.
2525
"""
2626

2727
method: MethodInfo[REQ, RES]
@@ -83,7 +83,7 @@ class EndpointSync(Generic[REQ, RES]):
8383
Represents a sync endpoint in a service.
8484
8585
Attributes:
86-
method: The method to map the RPC function.
86+
method: The method to map to the RPC function.
8787
"""
8888

8989
method: MethodInfo[REQ, RES]

src/connectrpc/_server_sync.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,14 @@ def _process_headers(headers: dict) -> Headers:
9898
def prepare_response_headers(
9999
base_headers: dict[str, list[str]], selected_encoding: str
100100
) -> dict[str, list[str]]:
101-
"""Prepare response headers and determine if compression should be used.
101+
"""Prepare response headers with the selected compression encoding.
102102
103103
Args:
104-
base_headers: Base response headers
105-
selected_encoding: Selected compression encoding
106-
compressed_size: Size of compressed content (if compression was attempted)
104+
base_headers: Base response headers.
105+
selected_encoding: Selected compression encoding.
107106
108107
Returns:
109-
tuple[dict, bool]: Final headers and whether to use compression
108+
The final response headers with content-encoding set.
110109
"""
111110
headers = base_headers.copy()
112111

@@ -173,7 +172,8 @@ def __init__(
173172
"""Initialize the WSGI application.
174173
175174
Args:
176-
endpoints: A mapping of URL paths to service endpoints.
175+
endpoints: A mapping of URL paths to endpoints. Typically provided directly
176+
by generated code from the Connect Python plugin.
177177
interceptors: A sequence of interceptors to apply to the endpoints.
178178
read_max_bytes: Maximum size of request messages.
179179
compressions: Supported compression algorithms. If unset, defaults to gzip.

src/connectrpc/compression/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ class Compression(Protocol):
1111
1212
By default, gzip compression is used. Other compression methods can be
1313
used by specifying implementations of this protocol. We provide standard
14-
implementations for
14+
implementations for:
1515
16-
- br (connectrpc.compression.brotli.BrotliCompression) - requires the `brotli` dependency
17-
- zstd (connectrpc.compression.zstd.ZstdCompression) - requires the `zstandard` dependency
16+
- br ([BrotliCompression][connectrpc.compression.brotli.BrotliCompression]) -
17+
requires the `brotli` dependency.
18+
- zstd ([ZstdCompression][connectrpc.compression.zstd.ZstdCompression]) -
19+
requires the `zstandard` dependency.
1820
"""
1921

2022
def name(self) -> str:

src/connectrpc/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConnectError(Exception):
2121
If a server raises a ConnectError, the same exception content will be
2222
raised on the client as well. Errors surfacing on the client side such as
2323
timeouts will also be raised as a ConnectError with an appropriate
24-
code.
24+
[Code][].
2525
"""
2626

2727
def __init__(

0 commit comments

Comments
 (0)