Skip to content

stubtest-complete grpcio plugins #13932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2025
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
5 changes: 4 additions & 1 deletion pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
"stubs/geopandas",
"stubs/google-cloud-ndb",
"stubs/grpcio/grpc/__init__.pyi",
"stubs/grpcio/grpc_status/rpc_status.pyi",
"stubs/grpcio/grpc_channelz/v1",
"stubs/grpcio/grpc_health/v1/health_pb2_grpc.pyi",
"stubs/grpcio/grpc_reflection/v1alpha",
"stubs/grpcio/grpc_status",
"stubs/hdbcli/hdbcli/dbapi.pyi",
"stubs/html5lib",
"stubs/httplib2",
Expand Down
5 changes: 0 additions & 5 deletions stubs/grpcio/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@
grpc.RpcError.code
grpc.RpcError.details
grpc.RpcError.trailing_metadata

# Error: is inconsistent
# =============================
# Stub class is incomplete.
grpc_reflection.v1alpha._base.BaseReflectionServicer.__init__
162 changes: 77 additions & 85 deletions stubs/grpcio/grpc/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ class Future(abc.ABC, Generic[_TFutureValue]):
@abc.abstractmethod
def done(self) -> bool: ...
@abc.abstractmethod
def exception(self, timeout: float | None = ...) -> Exception | None: ...
def exception(self, timeout: float | None = None) -> Exception | None: ...
@abc.abstractmethod
def result(self, timeout: float | None = ...) -> _TFutureValue: ...
def result(self, timeout: float | None = None) -> _TFutureValue: ...
@abc.abstractmethod
def running(self) -> bool: ...

# FIXME: unsure of the exact return type here. Is it a traceback.StackSummary?
@abc.abstractmethod
def traceback(self, timeout: float | None = ...) -> Any: ...
def traceback(self, timeout: float | None = None): ...

# Create Client:

def insecure_channel(target: str, options: _Options | None = ..., compression: Compression | None = ...) -> Channel: ...
def insecure_channel(target: str, options: _Options | None = None, compression: Compression | None = None) -> Channel: ...
def secure_channel(
target: str, credentials: ChannelCredentials, options: _Options | None = ..., compression: Compression | None = ...
target: str, credentials: ChannelCredentials, options: _Options | None = None, compression: Compression | None = None
) -> Channel: ...

_Interceptor: TypeAlias = (
Expand All @@ -108,14 +108,14 @@ def intercept_channel(channel: Channel, *interceptors: _Interceptor[_TRequest, _
# Create Client Credentials:

def ssl_channel_credentials(
root_certificates: bytes | None = ..., private_key: bytes | None = ..., certificate_chain: bytes | None = ...
root_certificates: bytes | None = None, private_key: bytes | None = None, certificate_chain: bytes | None = None
) -> ChannelCredentials: ...
def local_channel_credentials(local_connect_type: LocalConnectionType = ...) -> ChannelCredentials: ...
def metadata_call_credentials(metadata_plugin: AuthMetadataPlugin, name: str | None = ...) -> CallCredentials: ...
def metadata_call_credentials(metadata_plugin: AuthMetadataPlugin, name: str | None = None) -> CallCredentials: ...
def access_token_call_credentials(access_token: str) -> CallCredentials: ...
def alts_channel_credentials(service_accounts: Sequence[str] | None = ...) -> ChannelCredentials: ...
def alts_channel_credentials(service_accounts: Sequence[str] | None = None) -> ChannelCredentials: ...
def compute_engine_channel_credentials(call_credentials: CallCredentials) -> ChannelCredentials: ...
def xds_channel_credentials(fallback_credentials: ChannelCredentials | None = ...) -> ChannelCredentials: ...
def xds_channel_credentials(fallback_credentials: ChannelCredentials | None = None) -> ChannelCredentials: ...

# GRPC docs say there should be at least two:
def composite_call_credentials(creds1: CallCredentials, creds2: CallCredentials, *rest: CallCredentials) -> CallCredentials: ...
Expand All @@ -129,12 +129,12 @@ def composite_channel_credentials(

def server(
thread_pool: futures.ThreadPoolExecutor,
handlers: list[GenericRpcHandler[Any, Any]] | None = ...,
interceptors: list[ServerInterceptor[Any, Any]] | None = ...,
options: _Options | None = ...,
maximum_concurrent_rpcs: int | None = ...,
compression: Compression | None = ...,
xds: bool = ...,
handlers: list[GenericRpcHandler[Any, Any]] | None = None,
interceptors: list[ServerInterceptor[Any, Any]] | None = None,
options: _Options | None = None,
maximum_concurrent_rpcs: int | None = None,
compression: Compression | None = None,
xds: bool = False,
) -> Server: ...

# Create Server Credentials:
Expand All @@ -143,17 +143,17 @@ _CertificateChainPair: TypeAlias = tuple[bytes, bytes]

def ssl_server_credentials(
private_key_certificate_chain_pairs: list[_CertificateChainPair],
root_certificates: bytes | None = ...,
require_client_auth: bool = ...,
root_certificates: bytes | None = None,
require_client_auth: bool = False,
) -> ServerCredentials: ...
def local_server_credentials(local_connect_type: LocalConnectionType = ...) -> ServerCredentials: ...
def ssl_server_certificate_configuration(
private_key_certificate_chain_pairs: list[_CertificateChainPair], root_certificates: bytes | None = ...
private_key_certificate_chain_pairs: list[_CertificateChainPair], root_certificates: bytes | None = None
) -> ServerCertificateConfiguration: ...
def dynamic_ssl_server_credentials(
initial_certificate_configuration: ServerCertificateConfiguration,
certificate_configuration_fetcher: Callable[[], ServerCertificateConfiguration],
require_client_authentication: bool = ...,
require_client_authentication: bool = False,
) -> ServerCredentials: ...
def alts_server_credentials() -> ServerCredentials: ...
def insecure_server_credentials() -> ServerCredentials: ...
Expand All @@ -174,23 +174,23 @@ class _Behaviour(Protocol):

def unary_unary_rpc_method_handler(
behavior: _Behaviour,
request_deserializer: _RequestDeserializer | None = ...,
response_serializer: _ResponseSerializer | None = ...,
request_deserializer: _RequestDeserializer | None = None,
response_serializer: _ResponseSerializer | None = None,
) -> RpcMethodHandler[Any, Any]: ...
def unary_stream_rpc_method_handler(
behavior: _Behaviour,
request_deserializer: _RequestDeserializer | None = ...,
response_serializer: _ResponseSerializer | None = ...,
request_deserializer: _RequestDeserializer | None = None,
response_serializer: _ResponseSerializer | None = None,
) -> RpcMethodHandler[Any, Any]: ...
def stream_unary_rpc_method_handler(
behavior: _Behaviour,
request_deserializer: _RequestDeserializer | None = ...,
response_serializer: _ResponseSerializer | None = ...,
request_deserializer: _RequestDeserializer | None = None,
response_serializer: _ResponseSerializer | None = None,
) -> RpcMethodHandler[Any, Any]: ...
def stream_stream_rpc_method_handler(
behavior: _Behaviour,
request_deserializer: _RequestDeserializer | None = ...,
response_serializer: _ResponseSerializer | None = ...,
request_deserializer: _RequestDeserializer | None = None,
response_serializer: _ResponseSerializer | None = None,
) -> RpcMethodHandler[Any, Any]: ...
def method_handlers_generic_handler(
service: str, method_handlers: dict[str, RpcMethodHandler[Any, Any]]
Expand Down Expand Up @@ -248,31 +248,31 @@ class Channel(abc.ABC):
def stream_stream(
self,
method: str,
request_serializer: _RequestSerializer | None = ...,
response_deserializer: _ResponseDeserializer | None = ...,
request_serializer: _RequestSerializer | None = None,
response_deserializer: _ResponseDeserializer | None = None,
) -> StreamStreamMultiCallable[Any, Any]: ...
@abc.abstractmethod
def stream_unary(
self,
method: str,
request_serializer: _RequestSerializer | None = ...,
response_deserializer: _ResponseDeserializer | None = ...,
request_serializer: _RequestSerializer | None = None,
response_deserializer: _ResponseDeserializer | None = None,
) -> StreamUnaryMultiCallable[Any, Any]: ...
@abc.abstractmethod
def subscribe(self, callback: Callable[[ChannelConnectivity], None], try_to_connect: bool = ...) -> None: ...
def subscribe(self, callback: Callable[[ChannelConnectivity], None], try_to_connect: bool = False) -> None: ...
@abc.abstractmethod
def unary_stream(
self,
method: str,
request_serializer: _RequestSerializer | None = ...,
response_deserializer: _ResponseDeserializer | None = ...,
request_serializer: _RequestSerializer | None = None,
response_deserializer: _ResponseDeserializer | None = None,
) -> UnaryStreamMultiCallable[Any, Any]: ...
@abc.abstractmethod
def unary_unary(
self,
method: str,
request_serializer: _RequestSerializer | None = ...,
response_deserializer: _ResponseDeserializer | None = ...,
request_serializer: _RequestSerializer | None = None,
response_deserializer: _ResponseDeserializer | None = None,
) -> UnaryUnaryMultiCallable[Any, Any]: ...
@abc.abstractmethod
def unsubscribe(self, callback: Callable[[ChannelConnectivity], None]) -> None: ...
Expand Down Expand Up @@ -303,7 +303,7 @@ 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 wait_for_termination(self, timeout: float | None = None) -> bool: ...

# Authentication & Authorization Objects:

Expand Down Expand Up @@ -538,34 +538,31 @@ class UnaryUnaryMultiCallable(abc.ABC, Generic[_TRequest, _TResponse]):
def __call__(
self,
request: _TRequest,
timeout: float | None = ...,
metadata: _Metadata | None = ...,
credentials: CallCredentials | None = ...,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: bool | None = ...,
compression: Compression | None = ...,
timeout: float | None = None,
metadata: _Metadata | None = None,
credentials: CallCredentials | None = None,
wait_for_ready: bool | None = None,
compression: Compression | None = None,
) -> _TResponse: ...
@abc.abstractmethod
def future(
self,
request: _TRequest,
timeout: float | None = ...,
metadata: _Metadata | None = ...,
credentials: CallCredentials | None = ...,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: bool | None = ...,
compression: Compression | None = ...,
timeout: float | None = None,
metadata: _Metadata | None = None,
credentials: CallCredentials | None = None,
wait_for_ready: bool | None = None,
compression: Compression | None = None,
) -> _CallFuture[_TResponse]: ...
@abc.abstractmethod
def with_call(
self,
request: _TRequest,
timeout: float | None = ...,
metadata: _Metadata | None = ...,
credentials: CallCredentials | None = ...,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: bool | None = ...,
compression: Compression | None = ...,
timeout: float | None = None,
metadata: _Metadata | None = None,
credentials: CallCredentials | None = None,
wait_for_ready: bool | None = None,
compression: Compression | None = None,
# FIXME: Return value is documented as "The response value for the RPC and a Call value for the RPC";
# this is slightly unclear so this return type is a best-effort guess.
) -> tuple[_TResponse, Call]: ...
Expand All @@ -575,47 +572,43 @@ class UnaryStreamMultiCallable(abc.ABC, Generic[_TRequest, _TResponse]):
def __call__(
self,
request: _TRequest,
timeout: float | None = ...,
metadata: _Metadata | None = ...,
credentials: CallCredentials | None = ...,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: bool | None = ...,
compression: Compression | None = ...,
timeout: float | None = None,
metadata: _Metadata | None = None,
credentials: CallCredentials | None = None,
wait_for_ready: bool | None = None,
compression: Compression | None = None,
) -> _CallIterator[_TResponse]: ...

class StreamUnaryMultiCallable(abc.ABC, Generic[_TRequest, _TResponse]):
@abc.abstractmethod
def __call__(
self,
request_iterator: Iterator[_TRequest],
timeout: float | None = ...,
metadata: _Metadata | None = ...,
credentials: CallCredentials | None = ...,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: bool | None = ...,
compression: Compression | None = ...,
timeout: float | None = None,
metadata: _Metadata | None = None,
credentials: CallCredentials | None = None,
wait_for_ready: bool | None = None,
compression: Compression | None = None,
) -> _TResponse: ...
@abc.abstractmethod
def future(
self,
request_iterator: Iterator[_TRequest],
timeout: float | None = ...,
metadata: _Metadata | None = ...,
credentials: CallCredentials | None = ...,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: bool | None = ...,
compression: Compression | None = ...,
timeout: float | None = None,
metadata: _Metadata | None = None,
credentials: CallCredentials | None = None,
wait_for_ready: bool | None = None,
compression: Compression | None = None,
) -> _CallFuture[_TResponse]: ...
@abc.abstractmethod
def with_call(
self,
request_iterator: Iterator[_TRequest],
timeout: float | None = ...,
metadata: _Metadata | None = ...,
credentials: CallCredentials | None = ...,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: bool | None = ...,
compression: Compression | None = ...,
timeout: float | None = None,
metadata: _Metadata | None = None,
credentials: CallCredentials | None = None,
wait_for_ready: bool | None = None,
compression: Compression | None = None,
# FIXME: Return value is documented as "The response value for the RPC and a Call value for the RPC";
# this is slightly unclear so this return type is a best-effort guess.
) -> tuple[_TResponse, Call]: ...
Expand All @@ -625,12 +618,11 @@ class StreamStreamMultiCallable(abc.ABC, Generic[_TRequest, _TResponse]):
def __call__(
self,
request_iterator: Iterator[_TRequest],
timeout: float | None = ...,
metadata: _Metadata | None = ...,
credentials: CallCredentials | None = ...,
# FIXME: optional bool seems weird, but that's what the docs suggest
wait_for_ready: bool | None = ...,
compression: Compression | None = ...,
timeout: float | None = None,
metadata: _Metadata | None = None,
credentials: CallCredentials | None = None,
wait_for_ready: bool | None = None,
compression: Compression | None = None,
) -> _CallIterator[_TResponse]: ...

# Runtime Protobuf Parsing:
Expand Down
Loading