Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lint:
uv run black --check .
uv run ruff check .
uv run mypy .
uv run pyright-python .

format:
uv run black .
uv run ruff check . --fix
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dev-dependencies = [
"ruff>=0.0.278",
"types-protobuf>=4.24.0.20240311",
"types-nanoid>=2.0.0.20240601",
"pyright>=1.1.389",
]

[tool.ruff]
Expand Down
13 changes: 5 additions & 8 deletions replit_river/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def set(self, carrier: TransportMessage, key: str, value: str) -> None:
logger.warning("unknown trace propagation key", extra={"key": key})


class GrpcContext(grpc.aio.ServicerContext):
class GrpcContext(grpc.aio.ServicerContext, Generic[RequestType, ResponseType]):
"""Represents a gRPC-compatible ServicerContext for River interop."""

def __init__(self, peer: str) -> None:
Expand Down Expand Up @@ -229,9 +229,8 @@ async def wrapped(
input: Channel[Any],
output: Channel[Any],
) -> None:
context = None
context: GrpcContext[RequestType, ResponseType] = GrpcContext(peer)
try:
context = GrpcContext(peer)
request = request_deserializer(await input.get())
response = method(request, context)
if isinstance(response, Awaitable):
Expand Down Expand Up @@ -287,9 +286,8 @@ async def wrapped(
input: Channel[Any],
output: Channel[Any],
) -> None:
context = None
context: GrpcContext[RequestType, ResponseType] = GrpcContext(peer)
try:
context = GrpcContext(peer)
request = request_deserializer(await input.get())
iterator = method(request, context)
if isinstance(iterator, AsyncIterable):
Expand Down Expand Up @@ -349,7 +347,7 @@ async def wrapped(
) -> None:
task_manager = BackgroundTaskManager()
try:
context = GrpcContext(peer)
context: GrpcContext[RequestType, ResponseType] = GrpcContext(peer)
request: Channel[RequestType] = Channel(MAX_MESSAGE_BUFFER_SIZE)

async def _convert_inputs() -> None:
Expand Down Expand Up @@ -426,9 +424,8 @@ async def wrapped(
output: Channel[Any],
) -> None:
task_manager = BackgroundTaskManager()
context = None
context: GrpcContext[RequestType, ResponseType] = GrpcContext(peer)
try:
context = GrpcContext(peer)
request: Channel[RequestType] = Channel(MAX_MESSAGE_BUFFER_SIZE)

async def _convert_inputs() -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_message_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def mock_transport_message(seq: int) -> TransportMessage:
seq=seq,
id="test",
ack=0,
from_="test",
from_="test", # type: ignore
to="test",
streamId="test",
controlFlags=0,
payload=0,
model_config={},
model_config={}, # type: ignore
)


Expand Down
24 changes: 24 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading