From 4ca1353c4110a657c9e8d71b96e1fa1b08608de2 Mon Sep 17 00:00:00 2001 From: Micah Denbraver Date: Fri, 25 Apr 2025 09:37:18 -0700 Subject: [PATCH 1/3] switch to explicit exclusions for missing stubs --- stubs/grpcio/@tests/stubtest_allowlist.txt | 28 ++++++++++++++++++++++ stubs/grpcio/METADATA.toml | 1 - 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/stubs/grpcio/@tests/stubtest_allowlist.txt b/stubs/grpcio/@tests/stubtest_allowlist.txt index dad6fb3e8ec4..9d62ae3ea363 100644 --- a/stubs/grpcio/@tests/stubtest_allowlist.txt +++ b/stubs/grpcio/@tests/stubtest_allowlist.txt @@ -9,3 +9,31 @@ grpc.RpcError.trailing_metadata # ============================= # Stub class is incomplete. grpc_reflection.v1alpha._base.BaseReflectionServicer.__init__ + +# Error: is not present in stub +# ============================= +# Missing stubs +grpc.Server.add_registered_method_handlers +grpc.ServicerContext.code +grpc.ServicerContext.details +grpc.__all__ +grpc.aio.EOF +grpc.aio.Server.add_registered_method_handlers +grpc.aio.__all__ +grpc.aio.init_grpc_aio +grpc.aio.shutdown_grpc_aio +grpc_channelz.v1.* +grpc_health.v1.* +grpc_reflection.v1alpha.* +grpc_status.rpc_status.__all__ +grpc_status.rpc_status.aio + +# Error: failed to find stubs +# ============================= +# Missing stubs +grpc._cython.cygrpc +grpc.beta.* +grpc.experimental.* +grpc.framework.* +grpc_reflection.v1alpha.proto_reflection_descriptor_database +grpc_reflection.v1alpha.reflection_pb2_grpc diff --git a/stubs/grpcio/METADATA.toml b/stubs/grpcio/METADATA.toml index 9c94f65fb2ef..b8d14b58989a 100644 --- a/stubs/grpcio/METADATA.toml +++ b/stubs/grpcio/METADATA.toml @@ -6,7 +6,6 @@ requires = [ ] [tool.stubtest] -ignore_missing_stub = true stubtest_requirements = [ "grpcio-channelz", "grpcio-health-checking", From ed6e6a29f685921193bd93a4f40fd3483e373590 Mon Sep 17 00:00:00 2001 From: Micah Denbraver Date: Fri, 25 Apr 2025 10:30:13 -0700 Subject: [PATCH 2/3] add __all__ for grpc and grpc.aio --- stubs/grpcio/@tests/stubtest_allowlist.txt | 6 +- stubs/grpcio/grpc/__init__.pyi | 67 ++++++++++++++++++++++ stubs/grpcio/grpc/aio/__init__.pyi | 46 ++++++++++++++- stubs/grpcio/grpc/aio/_typing.pyi | 8 +++ 4 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 stubs/grpcio/grpc/aio/_typing.pyi diff --git a/stubs/grpcio/@tests/stubtest_allowlist.txt b/stubs/grpcio/@tests/stubtest_allowlist.txt index 9d62ae3ea363..ca779b093ef0 100644 --- a/stubs/grpcio/@tests/stubtest_allowlist.txt +++ b/stubs/grpcio/@tests/stubtest_allowlist.txt @@ -16,12 +16,8 @@ grpc_reflection.v1alpha._base.BaseReflectionServicer.__init__ grpc.Server.add_registered_method_handlers grpc.ServicerContext.code grpc.ServicerContext.details -grpc.__all__ -grpc.aio.EOF grpc.aio.Server.add_registered_method_handlers -grpc.aio.__all__ -grpc.aio.init_grpc_aio -grpc.aio.shutdown_grpc_aio +grpc.aio._typing.* grpc_channelz.v1.* grpc_health.v1.* grpc_reflection.v1alpha.* diff --git a/stubs/grpcio/grpc/__init__.pyi b/stubs/grpcio/grpc/__init__.pyi index 8f370e86a0e6..9c769b321320 100644 --- a/stubs/grpcio/grpc/__init__.pyi +++ b/stubs/grpcio/grpc/__init__.pyi @@ -638,3 +638,70 @@ class StreamStreamMultiCallable(abc.ABC, Generic[_TRequest, _TResponse]): def protos(protobuf_path: str) -> ModuleType: ... def services(protobuf_path: str) -> ModuleType: ... def protos_and_services(protobuf_path: str) -> tuple[ModuleType, ModuleType]: ... + +__all__ = ( + "FutureTimeoutError", + "FutureCancelledError", + "Future", + "ChannelConnectivity", + "StatusCode", + "Status", + "RpcError", + "RpcContext", + "Call", + "ChannelCredentials", + "CallCredentials", + "AuthMetadataContext", + "AuthMetadataPluginCallback", + "AuthMetadataPlugin", + "Compression", + "ClientCallDetails", + "ServerCertificateConfiguration", + "ServerCredentials", + "LocalConnectionType", + "UnaryUnaryMultiCallable", + "UnaryStreamMultiCallable", + "StreamUnaryMultiCallable", + "StreamStreamMultiCallable", + "UnaryUnaryClientInterceptor", + "UnaryStreamClientInterceptor", + "StreamUnaryClientInterceptor", + "StreamStreamClientInterceptor", + "Channel", + "ServicerContext", + "RpcMethodHandler", + "HandlerCallDetails", + "GenericRpcHandler", + "ServiceRpcHandler", + "Server", + "ServerInterceptor", + "unary_unary_rpc_method_handler", + "unary_stream_rpc_method_handler", + "stream_unary_rpc_method_handler", + "stream_stream_rpc_method_handler", + "method_handlers_generic_handler", + "ssl_channel_credentials", + "metadata_call_credentials", + "access_token_call_credentials", + "composite_call_credentials", + "composite_channel_credentials", + "compute_engine_channel_credentials", + "local_channel_credentials", + "local_server_credentials", + "alts_channel_credentials", + "alts_server_credentials", + "ssl_server_credentials", + "ssl_server_certificate_configuration", + "dynamic_ssl_server_credentials", + "channel_ready_future", + "insecure_channel", + "secure_channel", + "intercept_channel", + "server", + "protos", + "services", + "protos_and_services", + "xds_channel_credentials", + "xds_server_credentials", + "insecure_server_credentials", +) diff --git a/stubs/grpcio/grpc/aio/__init__.pyi b/stubs/grpcio/grpc/aio/__init__.pyi index 8a9cb36bb9e6..6fde185508e6 100644 --- a/stubs/grpcio/grpc/aio/__init__.pyi +++ b/stubs/grpcio/grpc/aio/__init__.pyi @@ -6,6 +6,7 @@ from concurrent import futures from types import TracebackType from typing import Any, Generic, NoReturn, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias +from grpc.aio._typing import EOFType from grpc import ( CallCredentials, @@ -23,6 +24,7 @@ from grpc import ( _TRequest = TypeVar("_TRequest") _TResponse = TypeVar("_TResponse") +EOF = EOFType() # Exceptions: @@ -46,6 +48,9 @@ class AioRpcError(RpcError): def debug_error_string(self) -> str: ... def initial_metadata(self) -> Metadata: ... +def init_grpc_aio() -> None: ... +def shutdown_grpc_aio() -> None: ... + # Create Client: class ClientInterceptor(metaclass=abc.ABCMeta): ... @@ -154,7 +159,6 @@ class Server(metaclass=abc.ABCMeta): # Client-Side Context: _DoneCallbackType: TypeAlias = Callable[[Any], None] -_EOFType: TypeAlias = object class RpcContext(metaclass=abc.ABCMeta): @abc.abstractmethod @@ -188,7 +192,7 @@ class UnaryStreamCall(Call, Generic[_TRequest, _TResponse], metaclass=abc.ABCMet @abc.abstractmethod def __aiter__(self) -> AsyncIterator[_TResponse]: ... @abc.abstractmethod - async def read(self) -> _EOFType | _TResponse: ... + async def read(self) -> EOFType | _TResponse: ... class StreamUnaryCall(Call, Generic[_TRequest, _TResponse], metaclass=abc.ABCMeta): @abc.abstractmethod @@ -202,7 +206,7 @@ class StreamStreamCall(Call, Generic[_TRequest, _TResponse], metaclass=abc.ABCMe @abc.abstractmethod def __aiter__(self) -> AsyncIterator[_TResponse]: ... @abc.abstractmethod - async def read(self) -> _EOFType | _TResponse: ... + async def read(self) -> EOFType | _TResponse: ... @abc.abstractmethod async def write(self, request: _TRequest) -> None: ... @abc.abstractmethod @@ -453,3 +457,39 @@ class Metadata(Mapping[_MetadataKey, _MetadataValue]): def __contains__(self, key: object) -> bool: ... def __eq__(self, other: object) -> bool: ... def __add__(self, other: Any) -> Metadata: ... + +__all__ = ( + "init_grpc_aio", + "shutdown_grpc_aio", + "AioRpcError", + "RpcContext", + "Call", + "UnaryUnaryCall", + "UnaryStreamCall", + "StreamUnaryCall", + "StreamStreamCall", + "Channel", + "UnaryUnaryMultiCallable", + "UnaryStreamMultiCallable", + "StreamUnaryMultiCallable", + "StreamStreamMultiCallable", + "ClientCallDetails", + "ClientInterceptor", + "UnaryStreamClientInterceptor", + "UnaryUnaryClientInterceptor", + "StreamUnaryClientInterceptor", + "StreamStreamClientInterceptor", + "InterceptedUnaryUnaryCall", + "ServerInterceptor", + "insecure_channel", + "server", + "Server", + "ServicerContext", + "EOF", + "secure_channel", + "AbortError", + "BaseError", + "UsageError", + "InternalError", + "Metadata", +) diff --git a/stubs/grpcio/grpc/aio/_typing.pyi b/stubs/grpcio/grpc/aio/_typing.pyi new file mode 100644 index 000000000000..b26b3daa2446 --- /dev/null +++ b/stubs/grpcio/grpc/aio/_typing.pyi @@ -0,0 +1,8 @@ +from typing import Literal + +class EOFType: + def __bool__(self) -> Literal[False]: ... + def __len__(self) -> Literal[0]: ... + def _repr(self) -> Literal[""]: ... + def __repr__(self) -> Literal[""]: ... + def __str__(self) -> Literal[""]: ... From f2e9d6e11f57beacf3a8cfd9304816f0001ac1b8 Mon Sep 17 00:00:00 2001 From: Micah Denbraver Date: Sun, 27 Apr 2025 14:23:00 -0700 Subject: [PATCH 3/3] add some missing stubs --- stubs/grpcio/@tests/stubtest_allowlist.txt | 4 ---- stubs/grpcio/grpc/__init__.pyi | 7 ++++++- stubs/grpcio/grpc/aio/__init__.pyi | 5 ++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/stubs/grpcio/@tests/stubtest_allowlist.txt b/stubs/grpcio/@tests/stubtest_allowlist.txt index ca779b093ef0..628fe1a393a2 100644 --- a/stubs/grpcio/@tests/stubtest_allowlist.txt +++ b/stubs/grpcio/@tests/stubtest_allowlist.txt @@ -13,10 +13,6 @@ grpc_reflection.v1alpha._base.BaseReflectionServicer.__init__ # Error: is not present in stub # ============================= # Missing stubs -grpc.Server.add_registered_method_handlers -grpc.ServicerContext.code -grpc.ServicerContext.details -grpc.aio.Server.add_registered_method_handlers grpc.aio._typing.* grpc_channelz.v1.* grpc_health.v1.* diff --git a/stubs/grpcio/grpc/__init__.pyi b/stubs/grpcio/grpc/__init__.pyi index 9c769b321320..4ad79b2596aa 100644 --- a/stubs/grpcio/grpc/__init__.pyi +++ b/stubs/grpcio/grpc/__init__.pyi @@ -304,6 +304,9 @@ class Server(abc.ABC): # Block current thread until the server stops. Returns a bool # indicates if the operation times out. Timeout is in seconds. def wait_for_termination(self, timeout: float | None = ...) -> bool: ... + def add_registered_method_handlers( + self, service_name: str, method_handlers: dict[str, RpcMethodHandler[Any, Any]] + ) -> None: ... # Authentication & Authorization Objects: @@ -483,11 +486,13 @@ class ServicerContext(RpcContext, metaclass=abc.ABCMeta): def set_compression(self, compression: Compression) -> None: ... @abc.abstractmethod def set_trailing_metadata(self, trailing_metadata: _Metadata) -> None: ... + def trailing_metadata(self) -> _Metadata: ... # misnamed function 'details', does not align with status.proto, where it is called 'message': @abc.abstractmethod def set_details(self, details: str) -> None: ... - def trailing_metadata(self) -> _Metadata: ... + def code(self) -> StatusCode: ... + def details(self) -> str: ... # Service-Side Handler: diff --git a/stubs/grpcio/grpc/aio/__init__.pyi b/stubs/grpcio/grpc/aio/__init__.pyi index 6fde185508e6..7c370849f843 100644 --- a/stubs/grpcio/grpc/aio/__init__.pyi +++ b/stubs/grpcio/grpc/aio/__init__.pyi @@ -6,7 +6,6 @@ from concurrent import futures from types import TracebackType from typing import Any, Generic, NoReturn, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias -from grpc.aio._typing import EOFType from grpc import ( CallCredentials, @@ -21,6 +20,7 @@ from grpc import ( StatusCode, _Options, ) +from grpc.aio._typing import EOFType _TRequest = TypeVar("_TRequest") _TResponse = TypeVar("_TResponse") @@ -155,6 +155,9 @@ class Server(metaclass=abc.ABCMeta): # Returns a bool indicates if the operation times out. Timeout is in seconds. @abc.abstractmethod async def wait_for_termination(self, timeout: float | None = ...) -> bool: ... + def add_registered_method_handlers( + self, service_name: str, method_handlers: dict[str, RpcMethodHandler[Any, Any]] + ) -> None: ... # Client-Side Context: