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
6 changes: 3 additions & 3 deletions examples/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class GreeterService(greeter_pb2_grpc.GreeterServicer):
@inject
def SayHello( # noqa: N802
self,
request: greeter_pb2.HelloRequest, # ty: ignore[unresolved-attribute]
request: greeter_pb2.HelloRequest, # ty: ignore[missing-attribute]
_context: grpc.ServicerContext,
greeter: typing.Annotated[Greeter, FromDI(Greeter)],
) -> greeter_pb2.HelloReply: # ty: ignore[unresolved-attribute]
return greeter_pb2.HelloReply(message=greeter.greet(request.name)) # ty: ignore[unresolved-attribute]
) -> greeter_pb2.HelloReply: # ty: ignore[missing-attribute]
return greeter_pb2.HelloReply(message=greeter.greet(request.name)) # ty: ignore[missing-attribute]


def build_server(port: str = "127.0.0.1:0") -> tuple[grpc.Server, int, Container]:
Expand Down
12 changes: 6 additions & 6 deletions modern_di_grpc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ def _rewrap(
) -> grpc.RpcMethodHandler:
# grpc.RpcMethodHandler is an abc.ABC documenting these attributes only in its docstring (no annotated
# fields), so ty cannot resolve them on the concrete instances the runtime actually hands back.
deserializer = handler.request_deserializer # ty: ignore[unresolved-attribute]
serializer = handler.response_serializer # ty: ignore[unresolved-attribute]
if unary_unary := handler.unary_unary: # ty: ignore[unresolved-attribute]
deserializer = handler.request_deserializer # ty: ignore[missing-attribute]
serializer = handler.response_serializer # ty: ignore[missing-attribute]
if unary_unary := handler.unary_unary: # ty: ignore[missing-attribute]
return grpc.unary_unary_rpc_method_handler(unary_builder(unary_unary), deserializer, serializer)
if unary_stream := handler.unary_stream: # ty: ignore[unresolved-attribute]
if unary_stream := handler.unary_stream: # ty: ignore[missing-attribute]
return grpc.unary_stream_rpc_method_handler(stream_builder(unary_stream), deserializer, serializer)
if stream_unary := handler.stream_unary: # ty: ignore[unresolved-attribute]
if stream_unary := handler.stream_unary: # ty: ignore[missing-attribute]
return grpc.stream_unary_rpc_method_handler(unary_builder(stream_unary), deserializer, serializer)
if stream_stream := handler.stream_stream: # ty: ignore[unresolved-attribute]
if stream_stream := handler.stream_stream: # ty: ignore[missing-attribute]
return grpc.stream_stream_rpc_method_handler(stream_builder(stream_stream), deserializer, serializer)
return handler # pragma: no cover (every RpcMethodHandler sets exactly one behavior)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

# greeter_pb2 is generated by protoc; ty (like most static checkers) can't see its dynamically
# built message attributes, so alias them once here instead of an ignore comment on every use below.
HelloRequest = greeter_pb2.HelloRequest # ty: ignore[unresolved-attribute]
HelloReply = greeter_pb2.HelloReply # ty: ignore[unresolved-attribute]
HelloRequest = greeter_pb2.HelloRequest # ty: ignore[missing-attribute]
HelloReply = greeter_pb2.HelloReply # ty: ignore[missing-attribute]


class AioServicer(greeter_pb2_grpc.GreeterServicer):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests.protos import greeter_pb2, greeter_pb2_grpc


HelloRequest = greeter_pb2.HelloRequest # ty: ignore[unresolved-attribute]
HelloRequest = greeter_pb2.HelloRequest # ty: ignore[missing-attribute]


def test_example_resolves_and_greets() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ def test_public_surface_is_exactly_the_six_documented_symbols() -> None:


def test_proto_stubs_importable() -> None:
assert greeter_pb2.HelloRequest is not None # ty: ignore[unresolved-attribute]
assert greeter_pb2.HelloRequest is not None # ty: ignore[missing-attribute]
assert greeter_pb2_grpc.GreeterServicer is not None
10 changes: 5 additions & 5 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

# greeter_pb2 is generated by protoc; ty (like most static checkers) can't see its dynamically
# built message attributes, so alias them once here instead of an ignore comment on every use below.
HelloRequest = greeter_pb2.HelloRequest # ty: ignore[unresolved-attribute]
HelloReply = greeter_pb2.HelloReply # ty: ignore[unresolved-attribute]
HelloRequest = greeter_pb2.HelloRequest # ty: ignore[missing-attribute]
HelloReply = greeter_pb2.HelloReply # ty: ignore[missing-attribute]


class Servicer(greeter_pb2_grpc.GreeterServicer):
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_unknown_method_returns_unimplemented(sync_channel: grpc.Channel) -> Non
sync_channel.unary_unary("/greeter.Greeter/DoesNotExist")(b"")
# grpc.RpcError is an empty marker class; the actual raised instance is also a grpc.Call
# (code(), details(), ...), which ty can't see from the RpcError annotation alone.
assert excinfo.value.code() == grpc.StatusCode.UNIMPLEMENTED # ty: ignore[unresolved-attribute]
assert excinfo.value.code() == grpc.StatusCode.UNIMPLEMENTED # ty: ignore[missing-attribute]


def test_inject_without_interceptor_reports_missing_interceptor() -> None:
Expand All @@ -138,8 +138,8 @@ def test_inject_without_interceptor_reports_missing_interceptor() -> None:
greeter_pb2_grpc.GreeterStub(channel).SayHello(HelloRequest(name="a"))
finally:
server.stop(0)
assert excinfo.value.code() == grpc.StatusCode.UNKNOWN # ty: ignore[unresolved-attribute]
assert "DIInterceptor" in excinfo.value.details() # ty: ignore[unresolved-attribute]
assert excinfo.value.code() == grpc.StatusCode.UNKNOWN # ty: ignore[missing-attribute]
assert "DIInterceptor" in excinfo.value.details() # ty: ignore[missing-attribute]


async def test_app_finalizer_runs_on_root_close() -> None:
Expand Down
Loading