|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Optional, cast |
| 4 | +from typing_extensions import assert_type |
| 5 | + |
| 6 | +import grpc |
| 7 | + |
| 8 | +# Channel options: |
| 9 | +assert_type(grpc.insecure_channel("target", ()), grpc.Channel) |
| 10 | +assert_type(grpc.insecure_channel("target", (("a", "b"),)), grpc.Channel) |
| 11 | +assert_type(grpc.insecure_channel("target", (("a", "b"), ("c", "d"))), grpc.Channel) |
| 12 | + |
| 13 | +# Local channel credentials: |
| 14 | +creds = grpc.local_channel_credentials(grpc.LocalConnectionType.LOCAL_TCP) |
| 15 | +assert_type(creds, grpc.ChannelCredentials) |
| 16 | + |
| 17 | +# Other credential types: |
| 18 | +assert_type(grpc.alts_channel_credentials(), grpc.ChannelCredentials) |
| 19 | +assert_type(grpc.alts_server_credentials(), grpc.ServerCredentials) |
| 20 | +assert_type(grpc.compute_engine_channel_credentials(grpc.CallCredentials("")), grpc.ChannelCredentials) |
| 21 | +assert_type(grpc.insecure_server_credentials(), grpc.ServerCredentials) |
| 22 | + |
| 23 | +# XDS credentials: |
| 24 | +assert_type( |
| 25 | + grpc.xds_channel_credentials(grpc.local_channel_credentials(grpc.LocalConnectionType.LOCAL_TCP)), grpc.ChannelCredentials |
| 26 | +) |
| 27 | +assert_type(grpc.xds_server_credentials(grpc.insecure_server_credentials()), grpc.ServerCredentials) |
| 28 | + |
| 29 | +# Channel ready future |
| 30 | +channel = grpc.insecure_channel("target", ()) |
| 31 | +assert_type(grpc.channel_ready_future(channel).result(), None) |
| 32 | + |
| 33 | +# Channel options supports list: |
| 34 | +assert_type(grpc.insecure_channel("target", []), grpc.Channel) |
| 35 | +assert_type(grpc.insecure_channel("target", [("a", "b")]), grpc.Channel) |
| 36 | +assert_type(grpc.insecure_channel("target", [("a", "b"), ("c", "d")]), grpc.Channel) |
| 37 | + |
| 38 | +# Client call details optionals: |
| 39 | +call_details = grpc.ClientCallDetails() |
| 40 | +assert_type(call_details.method, str) |
| 41 | +assert_type(call_details.timeout, Optional[float]) |
| 42 | + |
| 43 | +# Call iterator |
| 44 | +call_iter = cast(grpc._CallIterator[str], None) |
| 45 | +for call in call_iter: |
| 46 | + assert_type(call, str) |
0 commit comments