diff --git a/grpc_health-stubs/v1/health_pb2.pyi b/grpc_health-stubs/v1/health_pb2.pyi new file mode 100644 index 0000000..f2b45a0 --- /dev/null +++ b/grpc_health-stubs/v1/health_pb2.pyi @@ -0,0 +1,66 @@ +import typing + +from google.protobuf.descriptor import ( + Descriptor, + EnumDescriptor, + FileDescriptor, +) + +from google.protobuf.internal.enum_type_wrapper import ( + _EnumTypeWrapper, +) + +from google.protobuf.message import ( + Message, +) + +from typing_extensions import ( + Literal, + TypeAlias, +) + + +DESCRIPTOR: FileDescriptor + +class HealthCheckRequest(Message): + DESCRIPTOR: Descriptor + SERVICE_FIELD_NUMBER: int + service: typing.Text + def __init__(self, + *, + service: typing.Text = ..., + ) -> None: ... + def ClearField(self, field_name: Literal["service",b"service"]) -> None: ... + +class HealthCheckResponse(Message): + DESCRIPTOR: Descriptor + class _ServingStatus: + ValueType = typing.NewType('ValueType', int) + V: TypeAlias = ValueType + + class _ServingStatusEnumTypeWrapper(_EnumTypeWrapper[HealthCheckResponse._ServingStatus.ValueType], type): + DESCRIPTOR: EnumDescriptor + UNKNOWN: HealthCheckResponse._ServingStatus.ValueType # 0 + SERVING: HealthCheckResponse._ServingStatus.ValueType # 1 + NOT_SERVING: HealthCheckResponse._ServingStatus.ValueType # 2 + SERVICE_UNKNOWN: HealthCheckResponse._ServingStatus.ValueType # 3 + """Used only by the Watch method.""" + + class ServingStatus(_ServingStatus, metaclass=_ServingStatusEnumTypeWrapper): + pass + + UNKNOWN: HealthCheckResponse.ServingStatus.ValueType # 0 + SERVING: HealthCheckResponse.ServingStatus.ValueType # 1 + NOT_SERVING: HealthCheckResponse.ServingStatus.ValueType # 2 + SERVICE_UNKNOWN: HealthCheckResponse.ServingStatus.ValueType # 3 + """Used only by the Watch method.""" + + + STATUS_FIELD_NUMBER: int + status: HealthCheckResponse.ServingStatus.ValueType + def __init__(self, + *, + status: HealthCheckResponse.ServingStatus.ValueType = ..., + ) -> None: ... + def ClearField(self, field_name: Literal["status",b"status"]) -> None: ... + diff --git a/grpc_health-stubs/v1/health_pb2_grpc.pyi b/grpc_health-stubs/v1/health_pb2_grpc.pyi new file mode 100644 index 0000000..53c4ff2 --- /dev/null +++ b/grpc_health-stubs/v1/health_pb2_grpc.pyi @@ -0,0 +1,42 @@ +from grpc import ( + Channel, + Server, + ServicerContext, + UnaryStreamMultiCallable, + UnaryUnaryMultiCallable, +) + +from .health_pb2 import ( + HealthCheckRequest, + HealthCheckResponse, +) + +from typing import ( + Iterator, +) + + +class HealthStub: + def __init__(self, channel: Channel) -> None: ... + Check: UnaryUnaryMultiCallable[ + HealthCheckRequest, + HealthCheckResponse] + + Watch: UnaryStreamMultiCallable[ + HealthCheckRequest, + HealthCheckResponse] + + +class HealthServicer: + def Check(self, + request: HealthCheckRequest, + context: ServicerContext, + ) -> HealthCheckResponse: ... + + def Watch(self, + request: HealthCheckRequest, + context: ServicerContext, + ) -> Iterator[HealthCheckResponse]: ... + + +def add_HealthServicer_to_server(servicer: HealthServicer, server: Server) -> None: ... diff --git a/grpc_health-stubs/v1/py.typed b/grpc_health-stubs/v1/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/typesafety/test_grpc.yml b/typesafety/test_grpc.yml index b10ce2a..4887383 100644 --- a/typesafety/test_grpc.yml +++ b/typesafety/test_grpc.yml @@ -222,3 +222,14 @@ server = typing.cast(aio.Server, None) enable_server_reflection(["foo"], server, None) +- case: issue_30_healthservicer_set + main: | + import typing + import grpc + from grpc_health.v1 import health, health_pb2, health_pb2_grpc + server = typing.cast(grpc.Server, None) + health_servicer = typing.cast(health.HealthServicer, None) + health_pb2_grpc.add_HealthServicer_to_server(health_servicer, server) + service = "service" + health_servicer.set(service, health_pb2.HealthCheckResponse.SERVING) +