Skip to content

Commit

Permalink
Sweep grpc module for differences
Browse files Browse the repository at this point in the history
  • Loading branch information
shabbyrobe committed Mar 12, 2023
1 parent 77962f8 commit a0c8bb1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
28 changes: 21 additions & 7 deletions grpc-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import enum
import threading
import typing
from concurrent import futures
from types import TracebackType
from types import ModuleType, TracebackType

__version__: str

Expand Down Expand Up @@ -85,27 +85,26 @@ def ssl_channel_credentials(
) -> ChannelCredentials:
...


def local_channel_credentials(
local_connect_type: LocalConnectionType = LocalConnectionType.LOCAL_TCP,
) -> ChannelCredentials:
...


def metadata_call_credentials(
metadata_plugin: AuthMetadataPlugin,
name: typing.Optional[str] = None,
) -> CallCredentials:
...


def access_token_call_credentials(access_token: str) -> CallCredentials:
...

def alts_channel_credentials(
service_accounts: typing.Optional[typing.Sequence[str]] = None,
) -> ChannelCredentials: ...

def compute_engine_channel_credentials() -> ChannelCredentials: ...

def xds_channel_credentials(
fallback_credentials: typing.Optional[ChannelCredentials] = None,
) -> ChannelCredentials: ...
Expand All @@ -118,8 +117,6 @@ def composite_call_credentials(
) -> CallCredentials:
...



# Compose a ChannelCredentials and one or more CallCredentials objects.
def composite_channel_credentials(
channel_credentials: ChannelCredentials,
Expand All @@ -138,6 +135,7 @@ def server(
options: typing.Optional[_Options] = None,
maximum_concurrent_rpcs: typing.Optional[int] = None,
compression: typing.Optional[Compression] = None,
xds: bool = False,
) -> Server:
...

Expand Down Expand Up @@ -175,7 +173,9 @@ def dynamic_ssl_server_credentials(
...

def alts_server_credentials() -> ServerCredentials: ...

def insecure_server_credentials() -> ServerCredentials: ...

def xds_server_credentials(
fallback_credentials: ServerCredentials,
) -> ServerCredentials: ...
Expand Down Expand Up @@ -566,6 +566,8 @@ class ServicerContext(RpcContext):
# misnamed function 'details', does not align with status.proto, where it is called 'message':
def set_details(self, details: str) -> None: ...

def trailing_metadata(self) -> Metadata: ...


"""Service-Side Handler"""

Expand Down Expand Up @@ -597,7 +599,7 @@ class GenericRpcHandler(typing.Generic[TRequest, TResponse]):
def service(self, handler_call_details: HandlerCallDetails) -> typing.Optional[RpcMethodHandler[TRequest, TResponse]]:
...

class ServiceRpcHandler:
class ServiceRpcHandler(GenericRpcHandler[TRequest, TResponse], typing.Generic[TRequest, TResponse]):
def service_name(self) -> str: ...


Expand Down Expand Up @@ -772,3 +774,15 @@ class Future(typing.Generic[TFutureValue]):
# FIXME: unsure of the exact return type here. Is it a traceback.StackSummary?
def traceback(self, timeout: typing.Optional[float] = None) -> typing.Any: ...


"""Runtime Protobuf Parsing"""

def protos(protobuf_path: str) -> ModuleType:
...

def services(protobuf_path: str) -> ModuleType:
...

def protos_and_services(protobuf_path: str) -> typing.Tuple[ModuleType, ModuleType]:
...

25 changes: 25 additions & 0 deletions typesafety/test_grpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,28 @@
server_interceptors = [typing.cast(grpc.aio.ServerInterceptor, "interceptor")]
grpc.aio.server(interceptors=server_interceptors)
- case: service_rpc_handler_inheritance
main: |
import typing
import grpc
class Request: pass
class Response: pass
def unary_unary_call(rq: Request, ctx: grpc.ServicerContext) -> Response:
reveal_type(rq) # N: Revealed type is "main.Request"
return Response()
class ServiceHandler(grpc.ServiceRpcHandler[Request, Response]):
def service(self, handler_call_details: grpc.HandlerCallDetails) -> typing.Optional[grpc.RpcMethodHandler[Request, Response]]:
rpc = grpc.RpcMethodHandler[Request, Response]()
rpc.unary_unary = unary_unary_call
return rpc
h = ServiceHandler()
ctx = grpc.ServicerContext()
svc = h.service(grpc.HandlerCallDetails())
if svc is not None and svc.unary_unary is not None:
svc.unary_unary(Request(), ctx)

0 comments on commit a0c8bb1

Please sign in to comment.