Skip to content

Commit cbbd1c6

Browse files
Updating the LRO call to return the final result: TranslationStatus model (Azure#37955)
* Generating SDK with the latest Typespec commit ID * Fixing sphinx error
1 parent a3b68b4 commit cbbd1c6

File tree

10 files changed

+155
-130
lines changed

10 files changed

+155
-130
lines changed

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_operations/_operations.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def __begin_translation_initial(
383383
@overload
384384
def _begin_translation(
385385
self, body: _models.StartTranslationDetails, *, content_type: str = "application/json", **kwargs: Any
386-
) -> LROPoller[None]:
386+
) -> LROPoller[_models.TranslationStatus]:
387387
"""Submit a document translation request to the Document Translation service.
388388
389389
Use this API to submit a bulk (batch) translation request to the Document
@@ -411,15 +411,16 @@ def _begin_translation(
411411
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
412412
Default value is "application/json".
413413
:paramtype content_type: str
414-
:return: An instance of LROPoller that returns None
415-
:rtype: ~azure.core.polling.LROPoller[None]
414+
:return: An instance of LROPoller that returns TranslationStatus. The TranslationStatus is
415+
compatible with MutableMapping
416+
:rtype: ~azure.core.polling.LROPoller[~azure.ai.translation.document.models.TranslationStatus]
416417
:raises ~azure.core.exceptions.HttpResponseError:
417418
"""
418419

419420
@overload
420421
def _begin_translation(
421422
self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
422-
) -> LROPoller[None]:
423+
) -> LROPoller[_models.TranslationStatus]:
423424
"""Submit a document translation request to the Document Translation service.
424425
425426
Use this API to submit a bulk (batch) translation request to the Document
@@ -447,15 +448,16 @@ def _begin_translation(
447448
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
448449
Default value is "application/json".
449450
:paramtype content_type: str
450-
:return: An instance of LROPoller that returns None
451-
:rtype: ~azure.core.polling.LROPoller[None]
451+
:return: An instance of LROPoller that returns TranslationStatus. The TranslationStatus is
452+
compatible with MutableMapping
453+
:rtype: ~azure.core.polling.LROPoller[~azure.ai.translation.document.models.TranslationStatus]
452454
:raises ~azure.core.exceptions.HttpResponseError:
453455
"""
454456

455457
@overload
456458
def _begin_translation(
457459
self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
458-
) -> LROPoller[None]:
460+
) -> LROPoller[_models.TranslationStatus]:
459461
"""Submit a document translation request to the Document Translation service.
460462
461463
Use this API to submit a bulk (batch) translation request to the Document
@@ -483,15 +485,16 @@ def _begin_translation(
483485
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
484486
Default value is "application/json".
485487
:paramtype content_type: str
486-
:return: An instance of LROPoller that returns None
487-
:rtype: ~azure.core.polling.LROPoller[None]
488+
:return: An instance of LROPoller that returns TranslationStatus. The TranslationStatus is
489+
compatible with MutableMapping
490+
:rtype: ~azure.core.polling.LROPoller[~azure.ai.translation.document.models.TranslationStatus]
488491
:raises ~azure.core.exceptions.HttpResponseError:
489492
"""
490493

491494
@distributed_trace
492495
def _begin_translation(
493496
self, body: Union[_models.StartTranslationDetails, JSON, IO[bytes]], **kwargs: Any
494-
) -> LROPoller[None]:
497+
) -> LROPoller[_models.TranslationStatus]:
495498
"""Submit a document translation request to the Document Translation service.
496499
497500
Use this API to submit a bulk (batch) translation request to the Document
@@ -517,15 +520,16 @@ def _begin_translation(
517520
:param body: Translation job submission batch request. Is one of the following types:
518521
StartTranslationDetails, JSON, IO[bytes] Required.
519522
:type body: ~azure.ai.translation.document.models.StartTranslationDetails or JSON or IO[bytes]
520-
:return: An instance of LROPoller that returns None
521-
:rtype: ~azure.core.polling.LROPoller[None]
523+
:return: An instance of LROPoller that returns TranslationStatus. The TranslationStatus is
524+
compatible with MutableMapping
525+
:rtype: ~azure.core.polling.LROPoller[~azure.ai.translation.document.models.TranslationStatus]
522526
:raises ~azure.core.exceptions.HttpResponseError:
523527
"""
524528
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
525529
_params = kwargs.pop("params", {}) or {}
526530

527531
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
528-
cls: ClsType[None] = kwargs.pop("cls", None)
532+
cls: ClsType[_models.TranslationStatus] = kwargs.pop("cls", None)
529533
polling: Union[bool, PollingMethod] = kwargs.pop("polling", True)
530534
lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
531535
cont_token: Optional[str] = kwargs.pop("continuation_token", None)
@@ -536,9 +540,17 @@ def _begin_translation(
536540
raw_result.http_response.read() # type: ignore
537541
kwargs.pop("error_map", None)
538542

539-
def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements
543+
def get_long_running_output(pipeline_response):
544+
response_headers = {}
545+
response = pipeline_response.http_response
546+
response_headers["Operation-Location"] = self._deserialize(
547+
"str", response.headers.get("Operation-Location")
548+
)
549+
550+
deserialized = _deserialize(_models.TranslationStatus, response.json())
540551
if cls:
541-
return cls(pipeline_response, None, {}) # type: ignore
552+
return cls(pipeline_response, deserialized, response_headers) # type: ignore
553+
return deserialized
542554

543555
path_format_arguments = {
544556
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
@@ -553,13 +565,15 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-
553565
else:
554566
polling_method = polling
555567
if cont_token:
556-
return LROPoller[None].from_continuation_token(
568+
return LROPoller[_models.TranslationStatus].from_continuation_token(
557569
polling_method=polling_method,
558570
continuation_token=cont_token,
559571
client=self._client,
560572
deserialization_callback=get_long_running_output,
561573
)
562-
return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore
574+
return LROPoller[_models.TranslationStatus](
575+
self._client, raw_result, get_long_running_output, polling_method # type: ignore
576+
)
563577

564578
@distributed_trace
565579
def list_translation_statuses(

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_serialization.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class _FixedOffset(datetime.tzinfo): # type: ignore
226226
:param datetime.timedelta offset: offset in timedelta format
227227
"""
228228

229-
def __init__(self, offset):
229+
def __init__(self, offset) -> None:
230230
self.__offset = offset
231231

232232
def utcoffset(self, dt):
@@ -598,7 +598,7 @@ class Serializer(object): # pylint: disable=too-many-public-methods
598598
"multiple": lambda x, y: x % y != 0,
599599
}
600600

601-
def __init__(self, classes: Optional[Mapping[str, type]] = None):
601+
def __init__(self, classes: Optional[Mapping[str, type]] = None) -> None:
602602
self.serialize_type = {
603603
"iso-8601": Serializer.serialize_iso,
604604
"rfc-1123": Serializer.serialize_rfc,
@@ -1452,7 +1452,7 @@ class Deserializer(object):
14521452

14531453
valid_date = re.compile(r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?")
14541454

1455-
def __init__(self, classes: Optional[Mapping[str, type]] = None):
1455+
def __init__(self, classes: Optional[Mapping[str, type]] = None) -> None:
14561456
self.deserialize_type = {
14571457
"iso-8601": Deserializer.deserialize_iso,
14581458
"rfc-1123": Deserializer.deserialize_rfc,

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_operations/_operations.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async def __begin_translation_initial(
122122
@overload
123123
async def _begin_translation(
124124
self, body: _models.StartTranslationDetails, *, content_type: str = "application/json", **kwargs: Any
125-
) -> AsyncLROPoller[None]:
125+
) -> AsyncLROPoller[_models.TranslationStatus]:
126126
"""Submit a document translation request to the Document Translation service.
127127
128128
Use this API to submit a bulk (batch) translation request to the Document
@@ -150,15 +150,17 @@ async def _begin_translation(
150150
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
151151
Default value is "application/json".
152152
:paramtype content_type: str
153-
:return: An instance of AsyncLROPoller that returns None
154-
:rtype: ~azure.core.polling.AsyncLROPoller[None]
153+
:return: An instance of AsyncLROPoller that returns TranslationStatus. The TranslationStatus is
154+
compatible with MutableMapping
155+
:rtype:
156+
~azure.core.polling.AsyncLROPoller[~azure.ai.translation.document.models.TranslationStatus]
155157
:raises ~azure.core.exceptions.HttpResponseError:
156158
"""
157159

158160
@overload
159161
async def _begin_translation(
160162
self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
161-
) -> AsyncLROPoller[None]:
163+
) -> AsyncLROPoller[_models.TranslationStatus]:
162164
"""Submit a document translation request to the Document Translation service.
163165
164166
Use this API to submit a bulk (batch) translation request to the Document
@@ -186,15 +188,17 @@ async def _begin_translation(
186188
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
187189
Default value is "application/json".
188190
:paramtype content_type: str
189-
:return: An instance of AsyncLROPoller that returns None
190-
:rtype: ~azure.core.polling.AsyncLROPoller[None]
191+
:return: An instance of AsyncLROPoller that returns TranslationStatus. The TranslationStatus is
192+
compatible with MutableMapping
193+
:rtype:
194+
~azure.core.polling.AsyncLROPoller[~azure.ai.translation.document.models.TranslationStatus]
191195
:raises ~azure.core.exceptions.HttpResponseError:
192196
"""
193197

194198
@overload
195199
async def _begin_translation(
196200
self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
197-
) -> AsyncLROPoller[None]:
201+
) -> AsyncLROPoller[_models.TranslationStatus]:
198202
"""Submit a document translation request to the Document Translation service.
199203
200204
Use this API to submit a bulk (batch) translation request to the Document
@@ -222,15 +226,17 @@ async def _begin_translation(
222226
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
223227
Default value is "application/json".
224228
:paramtype content_type: str
225-
:return: An instance of AsyncLROPoller that returns None
226-
:rtype: ~azure.core.polling.AsyncLROPoller[None]
229+
:return: An instance of AsyncLROPoller that returns TranslationStatus. The TranslationStatus is
230+
compatible with MutableMapping
231+
:rtype:
232+
~azure.core.polling.AsyncLROPoller[~azure.ai.translation.document.models.TranslationStatus]
227233
:raises ~azure.core.exceptions.HttpResponseError:
228234
"""
229235

230236
@distributed_trace_async
231237
async def _begin_translation(
232238
self, body: Union[_models.StartTranslationDetails, JSON, IO[bytes]], **kwargs: Any
233-
) -> AsyncLROPoller[None]:
239+
) -> AsyncLROPoller[_models.TranslationStatus]:
234240
"""Submit a document translation request to the Document Translation service.
235241
236242
Use this API to submit a bulk (batch) translation request to the Document
@@ -256,15 +262,17 @@ async def _begin_translation(
256262
:param body: Translation job submission batch request. Is one of the following types:
257263
StartTranslationDetails, JSON, IO[bytes] Required.
258264
:type body: ~azure.ai.translation.document.models.StartTranslationDetails or JSON or IO[bytes]
259-
:return: An instance of AsyncLROPoller that returns None
260-
:rtype: ~azure.core.polling.AsyncLROPoller[None]
265+
:return: An instance of AsyncLROPoller that returns TranslationStatus. The TranslationStatus is
266+
compatible with MutableMapping
267+
:rtype:
268+
~azure.core.polling.AsyncLROPoller[~azure.ai.translation.document.models.TranslationStatus]
261269
:raises ~azure.core.exceptions.HttpResponseError:
262270
"""
263271
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
264272
_params = kwargs.pop("params", {}) or {}
265273

266274
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
267-
cls: ClsType[None] = kwargs.pop("cls", None)
275+
cls: ClsType[_models.TranslationStatus] = kwargs.pop("cls", None)
268276
polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True)
269277
lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
270278
cont_token: Optional[str] = kwargs.pop("continuation_token", None)
@@ -275,9 +283,17 @@ async def _begin_translation(
275283
await raw_result.http_response.read() # type: ignore
276284
kwargs.pop("error_map", None)
277285

278-
def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements
286+
def get_long_running_output(pipeline_response):
287+
response_headers = {}
288+
response = pipeline_response.http_response
289+
response_headers["Operation-Location"] = self._deserialize(
290+
"str", response.headers.get("Operation-Location")
291+
)
292+
293+
deserialized = _deserialize(_models.TranslationStatus, response.json())
279294
if cls:
280-
return cls(pipeline_response, None, {}) # type: ignore
295+
return cls(pipeline_response, deserialized, response_headers) # type: ignore
296+
return deserialized
281297

282298
path_format_arguments = {
283299
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
@@ -293,13 +309,15 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-
293309
else:
294310
polling_method = polling
295311
if cont_token:
296-
return AsyncLROPoller[None].from_continuation_token(
312+
return AsyncLROPoller[_models.TranslationStatus].from_continuation_token(
297313
polling_method=polling_method,
298314
continuation_token=cont_token,
299315
client=self._client,
300316
deserialization_callback=get_long_running_output,
301317
)
302-
return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore
318+
return AsyncLROPoller[_models.TranslationStatus](
319+
self._client, raw_result, get_long_running_output, polling_method # type: ignore
320+
)
303321

304322
@distributed_trace
305323
def list_translation_statuses(

0 commit comments

Comments
 (0)