2424 Optional ,
2525 Sequence ,
2626 TypeVar ,
27- Union ,
2827 get_args ,
2928)
3029
4443P = TypeVar ("P" )
4544
4645# Type alias representing any client-side gRPC interceptor
47- ClientInterceptor = Union [
48- grpc .UnaryUnaryClientInterceptor ,
49- grpc .UnaryStreamClientInterceptor ,
50- grpc .StreamUnaryClientInterceptor ,
51- grpc .StreamStreamClientInterceptor ,
52- ]
46+ ClientInterceptor = (
47+ grpc .UnaryUnaryClientInterceptor
48+ | grpc .UnaryStreamClientInterceptor
49+ | grpc .StreamUnaryClientInterceptor
50+ | grpc .StreamStreamClientInterceptor
51+ )
5352
5453# Runtime tuple of gRPC client interceptor base classes for isinstance checks
5554_CLIENT_INTERCEPTOR_CLASSES = get_args (ClientInterceptor )
5857ChannelWrapperCallable = Callable [[grpc .Channel ], grpc .Channel ]
5958
6059# Generic type alias representing any channel wrapper (interceptor or callable)
61- ChannelWrapper = Union [ ClientInterceptor , ChannelWrapperCallable ]
60+ ChannelWrapper = ClientInterceptor | ChannelWrapperCallable
6261
6362
6463def _patch_callable_name (callable_ ):
@@ -447,7 +446,7 @@ def _modify_target_for_direct_path(target: str) -> str:
447446
448447def apply_channel_wrappers (
449448 channel : grpc .Channel ,
450- wrappers : Optional [ Sequence [ChannelWrapper ]] = None ,
449+ wrappers : Sequence [ChannelWrapper ] | None = None ,
451450) -> grpc .Channel :
452451 """Applies channel wrappers (client interceptors or channel-wrapping callables) to a gRPC channel.
453452
@@ -472,6 +471,7 @@ def apply_channel_wrappers(
472471 return channel
473472
474473 modified_channel = channel
474+ # Reverse the inputs to align with the behavior of grpc.create_channel(*interceptors)
475475 for wrapper in reversed (list (wrappers )):
476476 if isinstance (wrapper , _CLIENT_INTERCEPTOR_CLASSES ):
477477 modified_channel = grpc .intercept_channel (modified_channel , wrapper )
0 commit comments