Skip to content

Commit 2b2ea71

Browse files
authored
stubtest-complete grpcio plugins (#13932)
1 parent 8d4cafd commit 2b2ea71

29 files changed

+1321
-221
lines changed

pyrightconfig.stricter.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
"stubs/geopandas",
4646
"stubs/google-cloud-ndb",
4747
"stubs/grpcio/grpc/__init__.pyi",
48-
"stubs/grpcio/grpc_status/rpc_status.pyi",
48+
"stubs/grpcio/grpc_channelz/v1",
49+
"stubs/grpcio/grpc_health/v1/health_pb2_grpc.pyi",
50+
"stubs/grpcio/grpc_reflection/v1alpha",
51+
"stubs/grpcio/grpc_status",
4952
"stubs/hdbcli/hdbcli/dbapi.pyi",
5053
"stubs/html5lib",
5154
"stubs/httplib2",

stubs/grpcio/@tests/stubtest_allowlist.txt

-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,3 @@
44
grpc.RpcError.code
55
grpc.RpcError.details
66
grpc.RpcError.trailing_metadata
7-
8-
# Error: is inconsistent
9-
# =============================
10-
# Stub class is incomplete.
11-
grpc_reflection.v1alpha._base.BaseReflectionServicer.__init__

stubs/grpcio/grpc/__init__.pyi

+77-85
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,21 @@ class Future(abc.ABC, Generic[_TFutureValue]):
7979
@abc.abstractmethod
8080
def done(self) -> bool: ...
8181
@abc.abstractmethod
82-
def exception(self, timeout: float | None = ...) -> Exception | None: ...
82+
def exception(self, timeout: float | None = None) -> Exception | None: ...
8383
@abc.abstractmethod
84-
def result(self, timeout: float | None = ...) -> _TFutureValue: ...
84+
def result(self, timeout: float | None = None) -> _TFutureValue: ...
8585
@abc.abstractmethod
8686
def running(self) -> bool: ...
8787

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

9292
# Create Client:
9393

94-
def insecure_channel(target: str, options: _Options | None = ..., compression: Compression | None = ...) -> Channel: ...
94+
def insecure_channel(target: str, options: _Options | None = None, compression: Compression | None = None) -> Channel: ...
9595
def secure_channel(
96-
target: str, credentials: ChannelCredentials, options: _Options | None = ..., compression: Compression | None = ...
96+
target: str, credentials: ChannelCredentials, options: _Options | None = None, compression: Compression | None = None
9797
) -> Channel: ...
9898

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

110110
def ssl_channel_credentials(
111-
root_certificates: bytes | None = ..., private_key: bytes | None = ..., certificate_chain: bytes | None = ...
111+
root_certificates: bytes | None = None, private_key: bytes | None = None, certificate_chain: bytes | None = None
112112
) -> ChannelCredentials: ...
113113
def local_channel_credentials(local_connect_type: LocalConnectionType = ...) -> ChannelCredentials: ...
114-
def metadata_call_credentials(metadata_plugin: AuthMetadataPlugin, name: str | None = ...) -> CallCredentials: ...
114+
def metadata_call_credentials(metadata_plugin: AuthMetadataPlugin, name: str | None = None) -> CallCredentials: ...
115115
def access_token_call_credentials(access_token: str) -> CallCredentials: ...
116-
def alts_channel_credentials(service_accounts: Sequence[str] | None = ...) -> ChannelCredentials: ...
116+
def alts_channel_credentials(service_accounts: Sequence[str] | None = None) -> ChannelCredentials: ...
117117
def compute_engine_channel_credentials(call_credentials: CallCredentials) -> ChannelCredentials: ...
118-
def xds_channel_credentials(fallback_credentials: ChannelCredentials | None = ...) -> ChannelCredentials: ...
118+
def xds_channel_credentials(fallback_credentials: ChannelCredentials | None = None) -> ChannelCredentials: ...
119119

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

130130
def server(
131131
thread_pool: futures.ThreadPoolExecutor,
132-
handlers: list[GenericRpcHandler[Any, Any]] | None = ...,
133-
interceptors: list[ServerInterceptor[Any, Any]] | None = ...,
134-
options: _Options | None = ...,
135-
maximum_concurrent_rpcs: int | None = ...,
136-
compression: Compression | None = ...,
137-
xds: bool = ...,
132+
handlers: list[GenericRpcHandler[Any, Any]] | None = None,
133+
interceptors: list[ServerInterceptor[Any, Any]] | None = None,
134+
options: _Options | None = None,
135+
maximum_concurrent_rpcs: int | None = None,
136+
compression: Compression | None = None,
137+
xds: bool = False,
138138
) -> Server: ...
139139

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

144144
def ssl_server_credentials(
145145
private_key_certificate_chain_pairs: list[_CertificateChainPair],
146-
root_certificates: bytes | None = ...,
147-
require_client_auth: bool = ...,
146+
root_certificates: bytes | None = None,
147+
require_client_auth: bool = False,
148148
) -> ServerCredentials: ...
149149
def local_server_credentials(local_connect_type: LocalConnectionType = ...) -> ServerCredentials: ...
150150
def ssl_server_certificate_configuration(
151-
private_key_certificate_chain_pairs: list[_CertificateChainPair], root_certificates: bytes | None = ...
151+
private_key_certificate_chain_pairs: list[_CertificateChainPair], root_certificates: bytes | None = None
152152
) -> ServerCertificateConfiguration: ...
153153
def dynamic_ssl_server_credentials(
154154
initial_certificate_configuration: ServerCertificateConfiguration,
155155
certificate_configuration_fetcher: Callable[[], ServerCertificateConfiguration],
156-
require_client_authentication: bool = ...,
156+
require_client_authentication: bool = False,
157157
) -> ServerCredentials: ...
158158
def alts_server_credentials() -> ServerCredentials: ...
159159
def insecure_server_credentials() -> ServerCredentials: ...
@@ -174,23 +174,23 @@ class _Behaviour(Protocol):
174174

175175
def unary_unary_rpc_method_handler(
176176
behavior: _Behaviour,
177-
request_deserializer: _RequestDeserializer | None = ...,
178-
response_serializer: _ResponseSerializer | None = ...,
177+
request_deserializer: _RequestDeserializer | None = None,
178+
response_serializer: _ResponseSerializer | None = None,
179179
) -> RpcMethodHandler[Any, Any]: ...
180180
def unary_stream_rpc_method_handler(
181181
behavior: _Behaviour,
182-
request_deserializer: _RequestDeserializer | None = ...,
183-
response_serializer: _ResponseSerializer | None = ...,
182+
request_deserializer: _RequestDeserializer | None = None,
183+
response_serializer: _ResponseSerializer | None = None,
184184
) -> RpcMethodHandler[Any, Any]: ...
185185
def stream_unary_rpc_method_handler(
186186
behavior: _Behaviour,
187-
request_deserializer: _RequestDeserializer | None = ...,
188-
response_serializer: _ResponseSerializer | None = ...,
187+
request_deserializer: _RequestDeserializer | None = None,
188+
response_serializer: _ResponseSerializer | None = None,
189189
) -> RpcMethodHandler[Any, Any]: ...
190190
def stream_stream_rpc_method_handler(
191191
behavior: _Behaviour,
192-
request_deserializer: _RequestDeserializer | None = ...,
193-
response_serializer: _ResponseSerializer | None = ...,
192+
request_deserializer: _RequestDeserializer | None = None,
193+
response_serializer: _ResponseSerializer | None = None,
194194
) -> RpcMethodHandler[Any, Any]: ...
195195
def method_handlers_generic_handler(
196196
service: str, method_handlers: dict[str, RpcMethodHandler[Any, Any]]
@@ -248,31 +248,31 @@ class Channel(abc.ABC):
248248
def stream_stream(
249249
self,
250250
method: str,
251-
request_serializer: _RequestSerializer | None = ...,
252-
response_deserializer: _ResponseDeserializer | None = ...,
251+
request_serializer: _RequestSerializer | None = None,
252+
response_deserializer: _ResponseDeserializer | None = None,
253253
) -> StreamStreamMultiCallable[Any, Any]: ...
254254
@abc.abstractmethod
255255
def stream_unary(
256256
self,
257257
method: str,
258-
request_serializer: _RequestSerializer | None = ...,
259-
response_deserializer: _ResponseDeserializer | None = ...,
258+
request_serializer: _RequestSerializer | None = None,
259+
response_deserializer: _ResponseDeserializer | None = None,
260260
) -> StreamUnaryMultiCallable[Any, Any]: ...
261261
@abc.abstractmethod
262-
def subscribe(self, callback: Callable[[ChannelConnectivity], None], try_to_connect: bool = ...) -> None: ...
262+
def subscribe(self, callback: Callable[[ChannelConnectivity], None], try_to_connect: bool = False) -> None: ...
263263
@abc.abstractmethod
264264
def unary_stream(
265265
self,
266266
method: str,
267-
request_serializer: _RequestSerializer | None = ...,
268-
response_deserializer: _ResponseDeserializer | None = ...,
267+
request_serializer: _RequestSerializer | None = None,
268+
response_deserializer: _ResponseDeserializer | None = None,
269269
) -> UnaryStreamMultiCallable[Any, Any]: ...
270270
@abc.abstractmethod
271271
def unary_unary(
272272
self,
273273
method: str,
274-
request_serializer: _RequestSerializer | None = ...,
275-
response_deserializer: _ResponseDeserializer | None = ...,
274+
request_serializer: _RequestSerializer | None = None,
275+
response_deserializer: _ResponseDeserializer | None = None,
276276
) -> UnaryUnaryMultiCallable[Any, Any]: ...
277277
@abc.abstractmethod
278278
def unsubscribe(self, callback: Callable[[ChannelConnectivity], None]) -> None: ...
@@ -303,7 +303,7 @@ class Server(abc.ABC):
303303

304304
# Block current thread until the server stops. Returns a bool
305305
# indicates if the operation times out. Timeout is in seconds.
306-
def wait_for_termination(self, timeout: float | None = ...) -> bool: ...
306+
def wait_for_termination(self, timeout: float | None = None) -> bool: ...
307307

308308
# Authentication & Authorization Objects:
309309

@@ -538,34 +538,31 @@ class UnaryUnaryMultiCallable(abc.ABC, Generic[_TRequest, _TResponse]):
538538
def __call__(
539539
self,
540540
request: _TRequest,
541-
timeout: float | None = ...,
542-
metadata: _Metadata | None = ...,
543-
credentials: CallCredentials | None = ...,
544-
# FIXME: optional bool seems weird, but that's what the docs suggest
545-
wait_for_ready: bool | None = ...,
546-
compression: Compression | None = ...,
541+
timeout: float | None = None,
542+
metadata: _Metadata | None = None,
543+
credentials: CallCredentials | None = None,
544+
wait_for_ready: bool | None = None,
545+
compression: Compression | None = None,
547546
) -> _TResponse: ...
548547
@abc.abstractmethod
549548
def future(
550549
self,
551550
request: _TRequest,
552-
timeout: float | None = ...,
553-
metadata: _Metadata | None = ...,
554-
credentials: CallCredentials | None = ...,
555-
# FIXME: optional bool seems weird, but that's what the docs suggest
556-
wait_for_ready: bool | None = ...,
557-
compression: Compression | None = ...,
551+
timeout: float | None = None,
552+
metadata: _Metadata | None = None,
553+
credentials: CallCredentials | None = None,
554+
wait_for_ready: bool | None = None,
555+
compression: Compression | None = None,
558556
) -> _CallFuture[_TResponse]: ...
559557
@abc.abstractmethod
560558
def with_call(
561559
self,
562560
request: _TRequest,
563-
timeout: float | None = ...,
564-
metadata: _Metadata | None = ...,
565-
credentials: CallCredentials | None = ...,
566-
# FIXME: optional bool seems weird, but that's what the docs suggest
567-
wait_for_ready: bool | None = ...,
568-
compression: Compression | None = ...,
561+
timeout: float | None = None,
562+
metadata: _Metadata | None = None,
563+
credentials: CallCredentials | None = None,
564+
wait_for_ready: bool | None = None,
565+
compression: Compression | None = None,
569566
# FIXME: Return value is documented as "The response value for the RPC and a Call value for the RPC";
570567
# this is slightly unclear so this return type is a best-effort guess.
571568
) -> tuple[_TResponse, Call]: ...
@@ -575,47 +572,43 @@ class UnaryStreamMultiCallable(abc.ABC, Generic[_TRequest, _TResponse]):
575572
def __call__(
576573
self,
577574
request: _TRequest,
578-
timeout: float | None = ...,
579-
metadata: _Metadata | None = ...,
580-
credentials: CallCredentials | None = ...,
581-
# FIXME: optional bool seems weird, but that's what the docs suggest
582-
wait_for_ready: bool | None = ...,
583-
compression: Compression | None = ...,
575+
timeout: float | None = None,
576+
metadata: _Metadata | None = None,
577+
credentials: CallCredentials | None = None,
578+
wait_for_ready: bool | None = None,
579+
compression: Compression | None = None,
584580
) -> _CallIterator[_TResponse]: ...
585581

586582
class StreamUnaryMultiCallable(abc.ABC, Generic[_TRequest, _TResponse]):
587583
@abc.abstractmethod
588584
def __call__(
589585
self,
590586
request_iterator: Iterator[_TRequest],
591-
timeout: float | None = ...,
592-
metadata: _Metadata | None = ...,
593-
credentials: CallCredentials | None = ...,
594-
# FIXME: optional bool seems weird, but that's what the docs suggest
595-
wait_for_ready: bool | None = ...,
596-
compression: Compression | None = ...,
587+
timeout: float | None = None,
588+
metadata: _Metadata | None = None,
589+
credentials: CallCredentials | None = None,
590+
wait_for_ready: bool | None = None,
591+
compression: Compression | None = None,
597592
) -> _TResponse: ...
598593
@abc.abstractmethod
599594
def future(
600595
self,
601596
request_iterator: Iterator[_TRequest],
602-
timeout: float | None = ...,
603-
metadata: _Metadata | None = ...,
604-
credentials: CallCredentials | None = ...,
605-
# FIXME: optional bool seems weird, but that's what the docs suggest
606-
wait_for_ready: bool | None = ...,
607-
compression: Compression | None = ...,
597+
timeout: float | None = None,
598+
metadata: _Metadata | None = None,
599+
credentials: CallCredentials | None = None,
600+
wait_for_ready: bool | None = None,
601+
compression: Compression | None = None,
608602
) -> _CallFuture[_TResponse]: ...
609603
@abc.abstractmethod
610604
def with_call(
611605
self,
612606
request_iterator: Iterator[_TRequest],
613-
timeout: float | None = ...,
614-
metadata: _Metadata | None = ...,
615-
credentials: CallCredentials | None = ...,
616-
# FIXME: optional bool seems weird, but that's what the docs suggest
617-
wait_for_ready: bool | None = ...,
618-
compression: Compression | None = ...,
607+
timeout: float | None = None,
608+
metadata: _Metadata | None = None,
609+
credentials: CallCredentials | None = None,
610+
wait_for_ready: bool | None = None,
611+
compression: Compression | None = None,
619612
# FIXME: Return value is documented as "The response value for the RPC and a Call value for the RPC";
620613
# this is slightly unclear so this return type is a best-effort guess.
621614
) -> tuple[_TResponse, Call]: ...
@@ -625,12 +618,11 @@ class StreamStreamMultiCallable(abc.ABC, Generic[_TRequest, _TResponse]):
625618
def __call__(
626619
self,
627620
request_iterator: Iterator[_TRequest],
628-
timeout: float | None = ...,
629-
metadata: _Metadata | None = ...,
630-
credentials: CallCredentials | None = ...,
631-
# FIXME: optional bool seems weird, but that's what the docs suggest
632-
wait_for_ready: bool | None = ...,
633-
compression: Compression | None = ...,
621+
timeout: float | None = None,
622+
metadata: _Metadata | None = None,
623+
credentials: CallCredentials | None = None,
624+
wait_for_ready: bool | None = None,
625+
compression: Compression | None = None,
634626
) -> _CallIterator[_TResponse]: ...
635627

636628
# Runtime Protobuf Parsing:

0 commit comments

Comments
 (0)