File tree Expand file tree Collapse file tree
packages/google-api-core/google/api_core Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323 Iterator ,
2424 Optional ,
2525 Sequence ,
26+ TypeAlias ,
2627 TypeVar ,
28+ cast ,
2729 get_args ,
2830)
2931
4345P = TypeVar ("P" )
4446
4547# Type alias representing any client-side gRPC interceptor
46- ClientInterceptor = (
48+ ClientInterceptor : TypeAlias = (
4749 grpc .UnaryUnaryClientInterceptor
4850 | grpc .UnaryStreamClientInterceptor
4951 | grpc .StreamUnaryClientInterceptor
5456_CLIENT_INTERCEPTOR_CLASSES = get_args (ClientInterceptor )
5557
5658# Type alias representing a channel-wrapping callable
57- ChannelWrapperCallable = Callable [[grpc .Channel ], grpc .Channel ]
59+ ChannelWrapperCallable : TypeAlias = Callable [[grpc .Channel ], grpc .Channel ]
5860
5961# Generic type alias representing any channel wrapper (interceptor or callable)
60- ChannelWrapper = ClientInterceptor | ChannelWrapperCallable
62+ ChannelWrapper : TypeAlias = ClientInterceptor | ChannelWrapperCallable
6163
6264
6365def _patch_callable_name (callable_ ):
@@ -476,7 +478,8 @@ def apply_channel_wrappers(
476478 if isinstance (wrapper , _CLIENT_INTERCEPTOR_CLASSES ):
477479 modified_channel = grpc .intercept_channel (modified_channel , wrapper )
478480 elif callable (wrapper ):
479- modified_channel = wrapper (modified_channel )
481+ wrapper_callable = cast (ChannelWrapperCallable , wrapper )
482+ modified_channel = wrapper_callable (modified_channel )
480483 else :
481484 raise TypeError (
482485 f"Expected ChannelWrapper (ClientInterceptor or Callable[[Channel], Channel]), got { type (wrapper ).__name__ } "
You can’t perform that action at this time.
0 commit comments