1717import os
1818import re
1919from typing import (
20+ Callable ,
2021 Dict ,
2122 Mapping ,
2223 MutableMapping ,
@@ -563,7 +564,11 @@ def __init__(
563564 self ,
564565 * ,
565566 credentials : Optional [ga_credentials .Credentials ] = None ,
566- transport : Optional [Union [str , AttachedClustersTransport ]] = None ,
567+ transport : Optional [
568+ Union [
569+ str , AttachedClustersTransport , Callable [..., AttachedClustersTransport ]
570+ ]
571+ ] = None ,
567572 client_options : Optional [Union [client_options_lib .ClientOptions , dict ]] = None ,
568573 client_info : gapic_v1 .client_info .ClientInfo = DEFAULT_CLIENT_INFO ,
569574 ) -> None :
@@ -575,9 +580,11 @@ def __init__(
575580 credentials identify the application to the service; if none
576581 are specified, the client will attempt to ascertain the
577582 credentials from the environment.
578- transport (Union[str, AttachedClustersTransport]): The
579- transport to use. If set to None, a transport is chosen
580- automatically.
583+ transport (Optional[Union[str,AttachedClustersTransport,Callable[..., AttachedClustersTransport]]]):
584+ The transport to use, or a Callable that constructs and returns a new transport.
585+ If a Callable is given, it will be called with the same set of initialization
586+ arguments as used in the AttachedClustersTransport constructor.
587+ If set to None, a transport is chosen automatically.
581588 NOTE: "rest" transport functionality is currently in a
582589 beta state (preview). We welcome your feedback via an
583590 issue in this library's source repository.
@@ -689,8 +696,16 @@ def __init__(
689696 api_key_value
690697 )
691698
692- Transport = type (self ).get_transport_class (cast (str , transport ))
693- self ._transport = Transport (
699+ transport_init : Union [
700+ Type [AttachedClustersTransport ],
701+ Callable [..., AttachedClustersTransport ],
702+ ] = (
703+ type (self ).get_transport_class (transport )
704+ if isinstance (transport , str ) or transport is None
705+ else cast (Callable [..., AttachedClustersTransport ], transport )
706+ )
707+ # initialize with the provided callable or the passed in class
708+ self ._transport = transport_init (
694709 credentials = credentials ,
695710 credentials_file = self ._client_options .credentials_file ,
696711 host = self ._api_endpoint ,
@@ -819,19 +834,17 @@ def sample_create_attached_cluster():
819834
820835 """
821836 # Create or coerce a protobuf request object.
822- # Quick check: If we got a request object, we should *not* have
823- # gotten any keyword arguments that map to the request.
837+ # - Quick check: If we got a request object, we should *not* have
838+ # gotten any keyword arguments that map to the request.
824839 has_flattened_params = any ([parent , attached_cluster , attached_cluster_id ])
825840 if request is not None and has_flattened_params :
826841 raise ValueError (
827842 "If the `request` argument is set, then none of "
828843 "the individual field arguments should be set."
829844 )
830845
831- # Minor optimization to avoid making a copy if the user passes
832- # in a attached_service.CreateAttachedClusterRequest.
833- # There's no risk of modifying the input as we've already verified
834- # there are no flattened fields.
846+ # - Use the request object if provided (there's no risk of modifying the input as
847+ # there are no flattened fields), or create one.
835848 if not isinstance (request , attached_service .CreateAttachedClusterRequest ):
836849 request = attached_service .CreateAttachedClusterRequest (request )
837850 # If we have keyword arguments corresponding to fields on the
@@ -974,19 +987,17 @@ def sample_update_attached_cluster():
974987
975988 """
976989 # Create or coerce a protobuf request object.
977- # Quick check: If we got a request object, we should *not* have
978- # gotten any keyword arguments that map to the request.
990+ # - Quick check: If we got a request object, we should *not* have
991+ # gotten any keyword arguments that map to the request.
979992 has_flattened_params = any ([attached_cluster , update_mask ])
980993 if request is not None and has_flattened_params :
981994 raise ValueError (
982995 "If the `request` argument is set, then none of "
983996 "the individual field arguments should be set."
984997 )
985998
986- # Minor optimization to avoid making a copy if the user passes
987- # in a attached_service.UpdateAttachedClusterRequest.
988- # There's no risk of modifying the input as we've already verified
989- # there are no flattened fields.
999+ # - Use the request object if provided (there's no risk of modifying the input as
1000+ # there are no flattened fields), or create one.
9901001 if not isinstance (request , attached_service .UpdateAttachedClusterRequest ):
9911002 request = attached_service .UpdateAttachedClusterRequest (request )
9921003 # If we have keyword arguments corresponding to fields on the
@@ -1129,19 +1140,17 @@ def sample_import_attached_cluster():
11291140
11301141 """
11311142 # Create or coerce a protobuf request object.
1132- # Quick check: If we got a request object, we should *not* have
1133- # gotten any keyword arguments that map to the request.
1143+ # - Quick check: If we got a request object, we should *not* have
1144+ # gotten any keyword arguments that map to the request.
11341145 has_flattened_params = any ([parent , fleet_membership ])
11351146 if request is not None and has_flattened_params :
11361147 raise ValueError (
11371148 "If the `request` argument is set, then none of "
11381149 "the individual field arguments should be set."
11391150 )
11401151
1141- # Minor optimization to avoid making a copy if the user passes
1142- # in a attached_service.ImportAttachedClusterRequest.
1143- # There's no risk of modifying the input as we've already verified
1144- # there are no flattened fields.
1152+ # - Use the request object if provided (there's no risk of modifying the input as
1153+ # there are no flattened fields), or create one.
11451154 if not isinstance (request , attached_service .ImportAttachedClusterRequest ):
11461155 request = attached_service .ImportAttachedClusterRequest (request )
11471156 # If we have keyword arguments corresponding to fields on the
@@ -1257,19 +1266,17 @@ def sample_get_attached_cluster():
12571266
12581267 """
12591268 # Create or coerce a protobuf request object.
1260- # Quick check: If we got a request object, we should *not* have
1261- # gotten any keyword arguments that map to the request.
1269+ # - Quick check: If we got a request object, we should *not* have
1270+ # gotten any keyword arguments that map to the request.
12621271 has_flattened_params = any ([name ])
12631272 if request is not None and has_flattened_params :
12641273 raise ValueError (
12651274 "If the `request` argument is set, then none of "
12661275 "the individual field arguments should be set."
12671276 )
12681277
1269- # Minor optimization to avoid making a copy if the user passes
1270- # in a attached_service.GetAttachedClusterRequest.
1271- # There's no risk of modifying the input as we've already verified
1272- # there are no flattened fields.
1278+ # - Use the request object if provided (there's no risk of modifying the input as
1279+ # there are no flattened fields), or create one.
12731280 if not isinstance (request , attached_service .GetAttachedClusterRequest ):
12741281 request = attached_service .GetAttachedClusterRequest (request )
12751282 # If we have keyword arguments corresponding to fields on the
@@ -1380,19 +1387,17 @@ def sample_list_attached_clusters():
13801387
13811388 """
13821389 # Create or coerce a protobuf request object.
1383- # Quick check: If we got a request object, we should *not* have
1384- # gotten any keyword arguments that map to the request.
1390+ # - Quick check: If we got a request object, we should *not* have
1391+ # gotten any keyword arguments that map to the request.
13851392 has_flattened_params = any ([parent ])
13861393 if request is not None and has_flattened_params :
13871394 raise ValueError (
13881395 "If the `request` argument is set, then none of "
13891396 "the individual field arguments should be set."
13901397 )
13911398
1392- # Minor optimization to avoid making a copy if the user passes
1393- # in a attached_service.ListAttachedClustersRequest.
1394- # There's no risk of modifying the input as we've already verified
1395- # there are no flattened fields.
1399+ # - Use the request object if provided (there's no risk of modifying the input as
1400+ # there are no flattened fields), or create one.
13961401 if not isinstance (request , attached_service .ListAttachedClustersRequest ):
13971402 request = attached_service .ListAttachedClustersRequest (request )
13981403 # If we have keyword arguments corresponding to fields on the
@@ -1525,19 +1530,17 @@ def sample_delete_attached_cluster():
15251530
15261531 """
15271532 # Create or coerce a protobuf request object.
1528- # Quick check: If we got a request object, we should *not* have
1529- # gotten any keyword arguments that map to the request.
1533+ # - Quick check: If we got a request object, we should *not* have
1534+ # gotten any keyword arguments that map to the request.
15301535 has_flattened_params = any ([name ])
15311536 if request is not None and has_flattened_params :
15321537 raise ValueError (
15331538 "If the `request` argument is set, then none of "
15341539 "the individual field arguments should be set."
15351540 )
15361541
1537- # Minor optimization to avoid making a copy if the user passes
1538- # in a attached_service.DeleteAttachedClusterRequest.
1539- # There's no risk of modifying the input as we've already verified
1540- # there are no flattened fields.
1542+ # - Use the request object if provided (there's no risk of modifying the input as
1543+ # there are no flattened fields), or create one.
15411544 if not isinstance (request , attached_service .DeleteAttachedClusterRequest ):
15421545 request = attached_service .DeleteAttachedClusterRequest (request )
15431546 # If we have keyword arguments corresponding to fields on the
@@ -1650,19 +1653,17 @@ def sample_get_attached_server_config():
16501653
16511654 """
16521655 # Create or coerce a protobuf request object.
1653- # Quick check: If we got a request object, we should *not* have
1654- # gotten any keyword arguments that map to the request.
1656+ # - Quick check: If we got a request object, we should *not* have
1657+ # gotten any keyword arguments that map to the request.
16551658 has_flattened_params = any ([name ])
16561659 if request is not None and has_flattened_params :
16571660 raise ValueError (
16581661 "If the `request` argument is set, then none of "
16591662 "the individual field arguments should be set."
16601663 )
16611664
1662- # Minor optimization to avoid making a copy if the user passes
1663- # in a attached_service.GetAttachedServerConfigRequest.
1664- # There's no risk of modifying the input as we've already verified
1665- # there are no flattened fields.
1665+ # - Use the request object if provided (there's no risk of modifying the input as
1666+ # there are no flattened fields), or create one.
16661667 if not isinstance (request , attached_service .GetAttachedServerConfigRequest ):
16671668 request = attached_service .GetAttachedServerConfigRequest (request )
16681669 # If we have keyword arguments corresponding to fields on the
@@ -1795,19 +1796,17 @@ def sample_generate_attached_cluster_install_manifest():
17951796
17961797 """
17971798 # Create or coerce a protobuf request object.
1798- # Quick check: If we got a request object, we should *not* have
1799- # gotten any keyword arguments that map to the request.
1799+ # - Quick check: If we got a request object, we should *not* have
1800+ # gotten any keyword arguments that map to the request.
18001801 has_flattened_params = any ([parent , attached_cluster_id ])
18011802 if request is not None and has_flattened_params :
18021803 raise ValueError (
18031804 "If the `request` argument is set, then none of "
18041805 "the individual field arguments should be set."
18051806 )
18061807
1807- # Minor optimization to avoid making a copy if the user passes
1808- # in a attached_service.GenerateAttachedClusterInstallManifestRequest.
1809- # There's no risk of modifying the input as we've already verified
1810- # there are no flattened fields.
1808+ # - Use the request object if provided (there's no risk of modifying the input as
1809+ # there are no flattened fields), or create one.
18111810 if not isinstance (
18121811 request , attached_service .GenerateAttachedClusterInstallManifestRequest
18131812 ):
@@ -1902,10 +1901,8 @@ def sample_generate_attached_cluster_agent_token():
19021901
19031902 """
19041903 # Create or coerce a protobuf request object.
1905- # Minor optimization to avoid making a copy if the user passes
1906- # in a attached_service.GenerateAttachedClusterAgentTokenRequest.
1907- # There's no risk of modifying the input as we've already verified
1908- # there are no flattened fields.
1904+ # - Use the request object if provided (there's no risk of modifying the input as
1905+ # there are no flattened fields), or create one.
19091906 if not isinstance (
19101907 request , attached_service .GenerateAttachedClusterAgentTokenRequest
19111908 ):
0 commit comments