@@ -50,6 +50,7 @@ public void run() {
5050
5151 private void generateService (PythonWriter writer ) {
5252 var serviceSymbol = symbolProvider .toSymbol (service );
53+ writer .addLocallyDefinedSymbol (serviceSymbol );
5354 var configSymbol = CodegenUtils .getConfigSymbol (context .settings ());
5455 var pluginSymbol = CodegenUtils .getPluginSymbol (context .settings ());
5556 writer .addLogger ();
@@ -71,7 +72,6 @@ private void generateService(PythonWriter writer) {
7172 }
7273
7374 writer .addDependency (SmithyPythonDependency .SMITHY_CORE );
74- writer .addImport ("smithy_core.retries" , "RetryStrategyResolver" );
7575 writer .write ("""
7676 def __init__(self, config: $1T | None = None, plugins: list[$2T] | None = None):
7777 $3C
@@ -86,12 +86,13 @@ def __init__(self, config: $1T | None = None, plugins: list[$2T] | None = None):
8686 for plugin in client_plugins:
8787 plugin(self._config)
8888
89- self._retry_strategy_resolver = RetryStrategyResolver ()
89+ self._retry_strategy_resolver = $5T ()
9090 """ ,
9191 configSymbol ,
9292 pluginSymbol ,
9393 writer .consumer (w -> writeConstructorDocs (w , serviceSymbol .getName ())),
94- writer .consumer (w -> writeDefaultPlugins (w , defaultPlugins )));
94+ writer .consumer (w -> writeDefaultPlugins (w , defaultPlugins )),
95+ RuntimeTypes .RETRY_STRATEGY_RESOLVER );
9596
9697 var topDownIndex = TopDownIndex .of (model );
9798 var eventStreamIndex = EventStreamIndex .of (model );
@@ -209,46 +210,45 @@ private void writeSharedOperationInit(
209210 }
210211
211212 writer .putContext ("operation" , symbolProvider .toSymbol (operation ));
212- writer .addImport ("smithy_core.aio.client" , "ClientCall" );
213- writer .addImport ("smithy_core.interceptors" , "InterceptorChain" );
214- writer .addImport ("smithy_core.types" , "TypedProperties" );
215- writer .addImport ("smithy_core.aio.client" , "RequestPipeline" );
216- writer .addImport ("smithy_core.exceptions" , "ExpectationNotMetError" );
217- writer .addImport ("smithy_core.retries" , "RetryStrategyOptions" );
218- writer .addImport ("smithy_core.interfaces.retries" , "RetryStrategy" );
219213 writer .addStdlibImport ("copy" , "deepcopy" );
220214
221215 writer .write ("""
222216 operation_plugins: list[Plugin] = [
223- $C
217+ $1C
224218 ]
225219 if plugins:
226220 operation_plugins.extend(plugins)
227221 config = deepcopy(self._config)
228222 for plugin in operation_plugins:
229223 plugin(config)
230224 if config.protocol is None or config.transport is None:
231- raise ExpectationNotMetError ("protocol and transport MUST be set on the config to make calls.")
225+ raise $2T ("protocol and transport MUST be set on the config to make calls.")
232226
233227 retry_strategy = await self._retry_strategy_resolver.resolve_retry_strategy(
234228 retry_strategy=config.retry_strategy
235229 )
236230
237- pipeline = RequestPipeline (
231+ pipeline = $3T (
238232 protocol=config.protocol,
239233 transport=config.transport
240234 )
241- call = ClientCall (
235+ call = $4T (
242236 input=input,
243237 operation=${operation:T},
244- context=TypedProperties ({"config": config}),
245- interceptor=InterceptorChain (config.interceptors),
238+ context=$5T ({"config": config}),
239+ interceptor=$6T (config.interceptors),
246240 auth_scheme_resolver=config.auth_scheme_resolver,
247241 supported_auth_schemes=config.auth_schemes,
248242 endpoint_resolver=config.endpoint_resolver,
249243 retry_strategy=retry_strategy,
250244 )
251- """ , writer .consumer (w -> writeDefaultPlugins (w , defaultPlugins )));
245+ """ ,
246+ writer .consumer (w -> writeDefaultPlugins (w , defaultPlugins )),
247+ RuntimeTypes .EXPECTATION_NOT_MET_ERROR ,
248+ RuntimeTypes .REQUEST_PIPELINE ,
249+ RuntimeTypes .CLIENT_CALL ,
250+ RuntimeTypes .TYPED_PROPERTIES ,
251+ RuntimeTypes .INTERCEPTOR_CHAIN );
252252
253253 }
254254
@@ -291,14 +291,14 @@ private void generateEventStreamOperation(PythonWriter writer, OperationShape op
291291 // the type declaration so much that it's no better than Any.
292292 if (inputStreamSymbol .isPresent ()) {
293293 if (outputStreamSymbol .isPresent ()) {
294- writer .addImport ( "smithy_core.aio.eventstream " , "DuplexEventStream" );
294+ writer .putContext ( "duplexEventStream " , RuntimeTypes . DUPLEX_EVENT_STREAM );
295295 var outputDocs = "A `DuplexEventStream` for bidirectional streaming." ;
296296 writer .write ("""
297297 async def ${operationName:L}(
298298 self,
299299 input: ${input:T},
300300 plugins: list[${plugin:T}] | None = None
301- ) -> DuplexEventStream [${inputStream:T}, ${outputStream:T}, ${output:T}]:
301+ ) -> ${duplexEventStream:T} [${inputStream:T}, ${outputStream:T}, ${output:T}]:
302302 ${C|}
303303 return await pipeline.duplex_stream(
304304 call,
@@ -309,14 +309,14 @@ private void generateEventStreamOperation(PythonWriter writer, OperationShape op
309309 """ ,
310310 writer .consumer (w -> writeSharedOperationInit (w , operation , input , output , outputDocs )));
311311 } else {
312- writer .addImport ( "smithy_core.aio.eventstream " , "InputEventStream" );
312+ writer .putContext ( "inputEventStream " , RuntimeTypes . INPUT_EVENT_STREAM );
313313 var outputDocs = "An `InputEventStream` for client-to-server streaming." ;
314314 writer .write ("""
315315 async def ${operationName:L}(
316316 self,
317317 input: ${input:T},
318318 plugins: list[${plugin:T}] | None = None
319- ) -> InputEventStream [${inputStream:T}, ${output:T}]:
319+ ) -> ${inputEventStream:T} [${inputStream:T}, ${output:T}]:
320320 ${C|}
321321 return await pipeline.input_stream(
322322 call,
@@ -326,14 +326,14 @@ private void generateEventStreamOperation(PythonWriter writer, OperationShape op
326326 writer .consumer (w -> writeSharedOperationInit (w , operation , input , output , outputDocs )));
327327 }
328328 } else {
329- writer .addImport ( "smithy_core.aio.eventstream " , "OutputEventStream" );
329+ writer .putContext ( "outputEventStream " , RuntimeTypes . OUTPUT_EVENT_STREAM );
330330 var outputDocs = "An `OutputEventStream` for server-to-client streaming." ;
331331 writer .write ("""
332332 async def ${operationName:L}(
333333 self,
334334 input: ${input:T},
335335 plugins: list[${plugin:T}] | None = None
336- ) -> OutputEventStream [${outputStream:T}, ${output:T}]:
336+ ) -> ${outputEventStream:T} [${outputStream:T}, ${output:T}]:
337337 ${C|}
338338 return await pipeline.output_stream(
339339 call,
0 commit comments