From 2caa64671ca37108a658a4fdb14b6b059c70238e Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 18 Jul 2022 14:50:32 -0700 Subject: [PATCH 1/4] add poller protocols --- .../azure/ai/textanalytics/__init__.py | 4 +- .../azure/ai/textanalytics/_lro.py | 254 ++++++------------ .../textanalytics/_text_analytics_client.py | 38 ++- .../azure/ai/textanalytics/aio/__init__.py | 4 +- .../azure/ai/textanalytics/aio/_lro_async.py | 252 ++++++----------- .../aio/_text_analytics_client_async.py | 39 ++- .../tests/test_custom_text.py | 10 +- .../tests/test_custom_text_async.py | 10 +- 8 files changed, 215 insertions(+), 396 deletions(-) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/__init__.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/__init__.py index a542a5dad3b2..bb78261c881c 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/__init__.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/__init__.py @@ -58,7 +58,7 @@ AnalyzeHealthcareEntitiesAction, ) -from ._lro import AnalyzeHealthcareEntitiesLROPoller, AnalyzeActionsLROPoller, TextAnalyticsLROPoller +from ._lro import AnalyzeHealthcareEntitiesLROPoller, AnalyzeActionsLROPoller, TextAnalysisLROPoller __all__ = [ "TextAnalyticsApiVersion", @@ -114,7 +114,7 @@ "ClassifyDocumentResult", "ClassificationCategory", "AnalyzeHealthcareEntitiesAction", - "TextAnalyticsLROPoller", + "TextAnalysisLROPoller", ] __version__ = VERSION diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py index 26b89701d1fb..3a3623c3b4c6 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py @@ -6,10 +6,10 @@ import base64 import functools import json -import datetime -from typing import Any, Optional, MutableMapping from urllib.parse import urlencode -from azure.core.polling._poller import PollingReturnType +from typing import Any, Mapping, Optional, Callable, TypeVar +from typing_extensions import Protocol, runtime_checkable +from azure.core.polling import PollingMethod from azure.core.exceptions import HttpResponseError from azure.core.polling import LROPoller from azure.core.polling.base_polling import ( @@ -25,6 +25,43 @@ _SUCCEEDED = frozenset(["succeeded", "partiallycompleted", "partiallysucceeded"]) +PollingReturnType = TypeVar("PollingReturnType") + + +@runtime_checkable +class TextAnalysisLROPoller(Protocol[PollingReturnType]): + """Implements a protocol which returned poller objects are consistent with. + """ + + @property + def details(self) -> Mapping[str, Any]: + ... + + def polling_method(self) -> PollingMethod[PollingReturnType]: + ... + + def continuation_token(self) -> str: + ... + + def status(self) -> str: + ... + + def result(self, timeout: Optional[int] = None) -> PollingReturnType: + ... + + def wait(self, timeout: Optional[float] = None) -> None: + ... + + def done(self) -> bool: + ... + + def add_done_callback(self, func: Callable) -> None: + ... + + def remove_done_callback(self, func: Callable) -> None: + ... + + class TextAnalyticsOperationResourcePolling(OperationResourcePolling): def __init__( self, operation_location_header="operation-location", show_stats=False @@ -174,52 +211,26 @@ def polling_method(self) -> AnalyzeHealthcareEntitiesLROPollingMethod: return self._polling_method # type: ignore @property - def created_on(self) -> datetime.datetime: - """When your healthcare entities job was created - - :return: When your healthcare entities job was created - :rtype: ~datetime.datetime - """ - return self.polling_method().created_on - - @property - def expires_on(self) -> datetime.datetime: - """When your healthcare entities job will expire - - :return: When your healthcare entities job will expire - :rtype: ~datetime.datetime - """ - return self.polling_method().expires_on - - @property - def last_modified_on(self) -> datetime.datetime: - """When your healthcare entities job was last modified - - :return: When your healthcare entities job was last modified - :rtype: ~datetime.datetime - """ - return self.polling_method().last_modified_on - - @property - def id(self) -> str: - """ID of your call to :func:`begin_analyze_healthcare_entities` - - :return: ID of your call to :func:`begin_analyze_healthcare_entities` - :rtype: str - """ - return self.polling_method().id - - @property - def display_name(self) -> str: - """Given display_name to the healthcare entities job - - :return: Display name of the healthcare entities job. - :rtype: str + def details(self) -> Mapping[str, Any]: + return { + "id": self.polling_method().id, + "created_on": self.polling_method().created_on, + "expires_on": self.polling_method().expires_on, + "display_name": self.polling_method().display_name, + "last_modified_on": self.polling_method().last_modified_on, + } - .. versionadded:: 2022-04-01-preview - *display_name* property. - """ - return self.polling_method().display_name + def __getattr__(self, item): + attrs = [ + "created_on", + "expires_on", + "display_name", + "last_modified_on", + "id" + ] + if item in attrs: + return self.details[item] + return self.__getattribute__(item) @classmethod def from_continuation_token( # type: ignore @@ -323,19 +334,19 @@ def display_name(self): def actions_failed_count(self): if not self._current_body: return None - return self._current_body.additional_properties["tasks"]["failed"] + return self._current_body.additional_properties.get("tasks", {}).get("failed", None) @property def actions_in_progress_count(self): if not self._current_body: return None - return self._current_body.additional_properties["tasks"]["inProgress"] + return self._current_body.additional_properties.get("tasks", {}).get("inProgress", None) @property def actions_succeeded_count(self): if not self._current_body: return None - return self._current_body.additional_properties["tasks"]["completed"] + return self._current_body.additional_properties.get("tasks", {}).get("completed", None) @property def last_modified_on(self): @@ -347,7 +358,7 @@ def last_modified_on(self): def total_actions_count(self): if not self._current_body: return None - return self._current_body.additional_properties["tasks"]["total"] + return self._current_body.additional_properties.get("tasks", {}).get("total", None) @property def id(self): @@ -370,137 +381,42 @@ def polling_method(self) -> AnalyzeActionsLROPollingMethod: return self._polling_method # type: ignore @property - def created_on(self) -> datetime.datetime: - """When your analyze job was created - - :return: When your analyze job was created - :rtype: ~datetime.datetime - """ - return self.polling_method().created_on - - @property - def expires_on(self) -> datetime.datetime: - """When your analyze job will expire - - :return: When your analyze job will expire - :rtype: ~datetime.datetime - """ - return self.polling_method().expires_on - - @property - def display_name(self) -> Optional[str]: - """The display name of your :func:`begin_analyze_actions` call. - - Corresponds to the `display_name` kwarg you pass to your - :func:`begin_analyze_actions` call. - - :return: The display name of your :func:`begin_analyze_actions` call. - :rtype: str - """ - return self.polling_method().display_name - - @property - def actions_failed_count(self) -> int: - """Total number of actions that have failed - - :return: Total number of actions that have failed - :rtype: int - """ - return self.polling_method().actions_failed_count - - @property - def actions_in_progress_count(self) -> int: - """Total number of actions currently in progress - - :return: Total number of actions currently in progress - :rtype: int - """ - return self.polling_method().actions_in_progress_count - - @property - def actions_succeeded_count(self) -> int: - """Total number of actions that succeeded - - :return: Total number of actions that succeeded - :rtype: int - """ - return self.polling_method().actions_succeeded_count - - @property - def last_modified_on(self) -> datetime.datetime: - """The last time your actions results were updated - - :return: The last time your actions results were updated - :rtype: ~datetime.datetime - """ - return self.polling_method().last_modified_on - - @property - def total_actions_count(self) -> int: - """Total number of actions you submitted - - :return: Total number of actions submitted - :rtype: int - """ - return self.polling_method().total_actions_count - - @property - def id(self) -> str: - """ID of your :func:`begin_analyze_actions` call. - - :return: ID of your :func:`begin_analyze_actions` call. - :rtype: str - """ - return self.polling_method().id - - @classmethod - def from_continuation_token( # type: ignore - cls, - polling_method: AnalyzeActionsLROPollingMethod, - continuation_token: str, - **kwargs: Any - ) -> "AnalyzeActionsLROPoller": # type: ignore - """ - :meta private: - """ - client, initial_response, deserialization_callback = polling_method.from_continuation_token( - continuation_token, **kwargs - ) - polling_method._lro_algorithms = [ # pylint: disable=protected-access - TextAnalyticsOperationResourcePolling( - show_stats=initial_response.context.options["show_stats"] - ) - ] - return cls( - client, - initial_response, - functools.partial(deserialization_callback, initial_response), - polling_method - ) - - -class TextAnalyticsLROPoller(LROPoller[PollingReturnType]): - def polling_method(self) -> AnalyzeActionsLROPollingMethod: - """Return the polling method associated to this poller.""" - return self._polling_method # type: ignore - - @property - def details(self) -> MutableMapping[str, Any]: + def details(self) -> Mapping[str, Any]: return { "id": self.polling_method().id, "created_on": self.polling_method().created_on, "expires_on": self.polling_method().expires_on, "display_name": self.polling_method().display_name, "last_modified_on": self.polling_method().last_modified_on, + "actions_failed_count": self.polling_method().actions_failed_count, + "actions_in_progress_count": self.polling_method().actions_in_progress_count, + "actions_succeeded_count": self.polling_method().actions_succeeded_count, + "total_actions_count": self.polling_method().total_actions_count, } + def __getattr__(self, item): + attrs = [ + "created_on", + "expires_on", + "display_name", + "actions_failed_count", + "actions_in_progress_count", + "actions_succeeded_count", + "total_actions_count", + "last_modified_on", + "id" + ] + if item in attrs: + return self.details[item] + return self.__getattribute__(item) + @classmethod def from_continuation_token( # type: ignore cls, polling_method: AnalyzeActionsLROPollingMethod, continuation_token: str, **kwargs: Any - ) -> "TextAnalyticsLROPoller": # type: ignore + ) -> "AnalyzeActionsLROPoller": # type: ignore """ :meta private: """ diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py index 19b3e8758a80..bebf83fc8f63 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py @@ -17,7 +17,7 @@ from azure.core.exceptions import HttpResponseError from azure.core.credentials import AzureKeyCredential from ._base_client import TextAnalyticsClientBase -from ._lro import AnalyzeActionsLROPoller, AnalyzeHealthcareEntitiesLROPoller, TextAnalyticsLROPoller +from ._lro import AnalyzeActionsLROPoller, AnalyzeHealthcareEntitiesLROPoller, TextAnalysisLROPoller from ._request_handlers import ( _validate_input, _determine_action_type, @@ -71,7 +71,7 @@ if TYPE_CHECKING: from azure.core.credentials import TokenCredential -AnalyzeActionsResponse = AnalyzeActionsLROPoller[ +AnalyzeActionsResponse = TextAnalysisLROPoller[ ItemPaged[ List[ Union[ @@ -1063,7 +1063,7 @@ def begin_analyze_actions( ] ], **kwargs: Any, - ) -> AnalyzeActionsLROPoller[ + ) -> TextAnalysisLROPoller[ ItemPaged[ List[ Union[ @@ -1117,7 +1117,7 @@ def begin_analyze_actions( Call `continuation_token()` on the poller object to save the long-running operation (LRO) state into an opaque token. Pass the value as the `continuation_token` keyword argument to restart the LRO from a saved state. - :return: An instance of an AnalyzeActionsLROPoller. Call `result()` on the poller + :return: An instance of an TextAnalysisLROPoller. Call `result()` on the poller object to return a pageable heterogeneous list of lists. This list of lists is first ordered by the documents you input, then ordered by the actions you input. For example, if you have documents input ["Hello", "world"], and actions @@ -1129,7 +1129,7 @@ def begin_analyze_actions( Then, you will get the :class:`~azure.ai.textanalytics.RecognizeEntitiesResult` and :class:`~azure.ai.textanalytics.AnalyzeSentimentResult` of "world". :rtype: - ~azure.ai.textanalytics.AnalyzeActionsLROPoller[~azure.core.paging.ItemPaged[ + ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[ list[RecognizeEntitiesResult or RecognizeLinkedEntitiesResult or RecognizePiiEntitiesResult or ExtractKeyPhrasesResult or AnalyzeSentimentResult or RecognizeCustomEntitiesResult or ClassifyDocumentResult or AnalyzeHealthcareEntitiesResult or DocumentError]]] @@ -1160,7 +1160,6 @@ def begin_analyze_actions( show_stats = kwargs.pop("show_stats", None) polling_interval = kwargs.pop("polling_interval", 5) language = language_arg if language_arg is not None else self._default_language - poller_cls = kwargs.pop("poller_cls", AnalyzeActionsLROPoller) bespoke = kwargs.pop("bespoke", False) if continuation_token: @@ -1232,7 +1231,6 @@ def begin_analyze_actions( **kwargs ), continuation_token=continuation_token, - poller_cls=poller_cls, **kwargs ) ) @@ -1297,7 +1295,7 @@ def begin_recognize_custom_entities( project_name, deployment_name, **kwargs: Any, - ) -> TextAnalyticsLROPoller[ItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]]: + ) -> TextAnalysisLROPoller[ItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]]: """Start a long-running custom named entity recognition operation. For information on regional support of custom features and how to train a model to @@ -1337,12 +1335,12 @@ def begin_recognize_custom_entities( state into an opaque token. Pass the value as the `continuation_token` keyword argument to restart the LRO from a saved state. :keyword str display_name: An optional display name to set for the requested analysis. - :return: An instance of an TextAnalyticsLROPoller. Call `result()` on the this + :return: An instance of an TextAnalysisLROPoller. Call `result()` on the this object to return a heterogeneous pageable of :class:`~azure.ai.textanalytics.RecognizeCustomEntitiesResult` and :class:`~azure.ai.textanalytics.DocumentError`. :rtype: - ~azure.ai.textanalytics.TextAnalyticsLROPoller[~azure.core.paging.ItemPaged[ + ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[ ~azure.ai.textanalytics.RecognizeCustomEntitiesResult or ~azure.ai.textanalytics.DocumentError]] :raises ~azure.core.exceptions.HttpResponseError: @@ -1366,11 +1364,11 @@ def begin_recognize_custom_entities( if continuation_token: return cast( - TextAnalyticsLROPoller[ItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]], + TextAnalysisLROPoller[ItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]], _get_result_from_continuation_token( self._client._client, # pylint: disable=protected-access continuation_token, - TextAnalyticsLROPoller, + AnalyzeActionsLROPoller, AnalyzeActionsLROPollingMethod( timeout=polling_interval, **kwargs @@ -1382,7 +1380,7 @@ def begin_recognize_custom_entities( try: return cast( - TextAnalyticsLROPoller[ + TextAnalysisLROPoller[ ItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]] ], self.begin_analyze_actions( @@ -1396,7 +1394,6 @@ def begin_recognize_custom_entities( ) ], polling_interval=polling_interval, - poller_cls=TextAnalyticsLROPoller, bespoke=True, **kwargs ) @@ -1415,7 +1412,7 @@ def begin_single_label_classify( project_name, deployment_name, **kwargs: Any, - ) -> TextAnalyticsLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]]: + ) -> TextAnalysisLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]]: """Start a long-running custom single label classification operation. For information on regional support of custom features and how to train a model to @@ -1451,12 +1448,12 @@ def begin_single_label_classify( state into an opaque token. Pass the value as the `continuation_token` keyword argument to restart the LRO from a saved state. :keyword str display_name: An optional display name to set for the requested analysis. - :return: An instance of an TextAnalyticsLROPoller. Call `result()` on the this + :return: An instance of an TextAnalysisLROPoller. Call `result()` on the this object to return a heterogeneous pageable of :class:`~azure.ai.textanalytics.ClassifyDocumentResult` and :class:`~azure.ai.textanalytics.DocumentError`. :rtype: - ~azure.ai.textanalytics.TextAnalyticsLROPoller[~azure.core.paging.ItemPaged[ + ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[ ~azure.ai.textanalytics.ClassifyDocumentResult or ~azure.ai.textanalytics.DocumentError]] :raises ~azure.core.exceptions.HttpResponseError: @@ -1479,11 +1476,11 @@ def begin_single_label_classify( if continuation_token: return cast( - TextAnalyticsLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]], + TextAnalysisLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]], _get_result_from_continuation_token( self._client._client, # pylint: disable=protected-access continuation_token, - TextAnalyticsLROPoller, + AnalyzeActionsLROPoller, AnalyzeActionsLROPollingMethod( timeout=polling_interval, **kwargs @@ -1495,7 +1492,7 @@ def begin_single_label_classify( try: return cast( - TextAnalyticsLROPoller[ + TextAnalysisLROPoller[ ItemPaged[Union[ClassifyDocumentResult, DocumentError]] ], self.begin_analyze_actions( @@ -1508,7 +1505,6 @@ def begin_single_label_classify( ) ], polling_interval=polling_interval, - poller_cls=TextAnalyticsLROPoller, bespoke=True, **kwargs ) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/__init__.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/__init__.py index 9ae666c2563f..c9879fe50423 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/__init__.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/__init__.py @@ -7,12 +7,12 @@ from ._lro_async import ( AsyncAnalyzeHealthcareEntitiesLROPoller, AsyncAnalyzeActionsLROPoller, - AsyncTextAnalyticsLROPoller, + AsyncTextAnalysisLROPoller, ) __all__ = [ "TextAnalyticsClient", "AsyncAnalyzeHealthcareEntitiesLROPoller", "AsyncAnalyzeActionsLROPoller", - "AsyncTextAnalyticsLROPoller", + "AsyncTextAnalysisLROPoller", ] diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_lro_async.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_lro_async.py index b5707fef7028..1bdb46527f07 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_lro_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_lro_async.py @@ -2,16 +2,16 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ -import datetime + import base64 import functools import json -from typing import Optional, Any, MutableMapping +from typing import Mapping, Any, TypeVar, Generator, Awaitable +from typing_extensions import Protocol, runtime_checkable from azure.core.exceptions import HttpResponseError -from azure.core.polling import AsyncLROPoller +from azure.core.polling import AsyncLROPoller, AsyncPollingMethod from azure.core.polling.base_polling import OperationFailed, BadStatus from azure.core.polling.async_base_polling import AsyncLROBasePolling -from azure.core.polling._async_poller import PollingReturnType from .._lro import TextAnalyticsOperationResourcePolling from .._generated.v2022_05_01.models import JobState @@ -20,6 +20,39 @@ _FAILED = frozenset(["failed"]) _SUCCEEDED = frozenset(["succeeded", "partiallycompleted", "partiallysucceeded"]) +PollingReturnType = TypeVar("PollingReturnType") + + +@runtime_checkable +class AsyncTextAnalysisLROPoller(Protocol[PollingReturnType], Awaitable): + """Implements a protocol which returned poller objects are consistent with. + """ + + @property + def details(self) -> Mapping[str, Any]: + ... + + def polling_method(self) -> AsyncPollingMethod[PollingReturnType]: + ... + + def continuation_token(self) -> str: + ... + + def status(self) -> str: + ... + + async def result(self) -> PollingReturnType: + ... + + async def wait(self) -> None: + ... + + def done(self) -> bool: + ... + + def __await__(self) -> Generator[Any, None, PollingReturnType]: + ... + class TextAnalyticsAsyncLROPollingMethod(AsyncLROBasePolling): def finished(self): @@ -148,52 +181,26 @@ def polling_method(self) -> AsyncAnalyzeHealthcareEntitiesLROPollingMethod: # t return self._polling_method # type: ignore @property - def created_on(self) -> datetime.datetime: - """When your healthcare entities job was created - - :return: When your healthcare entities job was created - :rtype: ~datetime.datetime - """ - return self.polling_method().created_on - - @property - def expires_on(self) -> datetime.datetime: - """When your healthcare entities job will expire - - :return: When your healthcare entities job will expire - :rtype: ~datetime.datetime - """ - return self.polling_method().expires_on - - @property - def last_modified_on(self) -> datetime.datetime: - """When your healthcare entities job was last modified - - :return: When your healthcare entities job was last modified - :rtype: ~datetime.datetime - """ - return self.polling_method().last_modified_on - - @property - def id(self) -> str: - """ID of your call to :func:`begin_analyze_healthcare_entities` - - :return: ID of your call to :func:`begin_analyze_healthcare_entities` - :rtype: str - """ - return self.polling_method().id - - @property - def display_name(self) -> str: - """Given display_name to the healthcare entities job - - :return: Display name of the healthcare entities job. - :rtype: str + def details(self) -> Mapping[str, Any]: + return { + "id": self.polling_method().id, + "created_on": self.polling_method().created_on, + "expires_on": self.polling_method().expires_on, + "display_name": self.polling_method().display_name, + "last_modified_on": self.polling_method().last_modified_on, + } - .. versionadded:: 2022-04-01-preview - *display_name* property. - """ - return self.polling_method().display_name + def __getattr__(self, item): + attrs = [ + "created_on", + "expires_on", + "display_name", + "last_modified_on", + "id" + ] + if item in attrs: + return self.details[item] + return self.__getattribute__(item) @classmethod def from_continuation_token( # type: ignore @@ -292,19 +299,19 @@ def expires_on(self): def actions_failed_count(self): if not self._current_body: return None - return self._current_body.additional_properties["tasks"]["failed"] + return self._current_body.additional_properties.get("tasks", {}).get("failed", None) @property def actions_in_progress_count(self): if not self._current_body: return None - return self._current_body.additional_properties["tasks"]["inProgress"] + return self._current_body.additional_properties.get("tasks", {}).get("inProgress", None) @property def actions_succeeded_count(self): if not self._current_body: return None - return self._current_body.additional_properties["tasks"]["completed"] + return self._current_body.additional_properties.get("tasks", {}).get("completed", None) @property def last_modified_on(self): @@ -316,7 +323,7 @@ def last_modified_on(self): def total_actions_count(self): if not self._current_body: return None - return self._current_body.additional_properties["tasks"]["total"] + return self._current_body.additional_properties.get("tasks", {}).get("total", None) @property def id(self): @@ -339,137 +346,42 @@ def polling_method(self) -> AsyncAnalyzeActionsLROPollingMethod: # type: ignore return self._polling_method # type: ignore @property - def created_on(self) -> datetime.datetime: - """When your analyze job was created - - :return: When your analyze job was created - :rtype: ~datetime.datetime - """ - return self.polling_method().created_on - - @property - def display_name(self) -> Optional[str]: - """The display name of your :func:`begin_analyze_actions` call. - - Corresponds to the `display_name` kwarg you pass to your - :func:`begin_analyze_actions` call. - - :return: The display name of your :func:`begin_analyze_actions` call. - :rtype: str - """ - return self.polling_method().display_name - - @property - def expires_on(self) -> datetime.datetime: - """When your analyze job will expire - - :return: When your analyze job will expire - :rtype: ~datetime.datetime - """ - return self.polling_method().expires_on - - @property - def actions_failed_count(self) -> int: - """Total number of actions that have failed - - :return: Total number of actions that have failed - :rtype: int - """ - return self.polling_method().actions_failed_count - - @property - def actions_in_progress_count(self) -> int: - """Total number of actions currently in progress - - :return: Total number of actions currently in progress - :rtype: int - """ - return self.polling_method().actions_in_progress_count - - @property - def actions_succeeded_count(self) -> int: - """Total number of actions that succeeded - - :return: Total number of actions that succeeded - :rtype: int - """ - return self.polling_method().actions_succeeded_count - - @property - def last_modified_on(self) -> datetime.datetime: - """The last time your actions results were updated - - :return: The last time your actions results were updated - :rtype: ~datetime.datetime - """ - return self.polling_method().last_modified_on - - @property - def total_actions_count(self) -> int: - """Total number of actions you submitted - - :return: Total number of actions submitted - :rtype: int - """ - return self.polling_method().total_actions_count - - @property - def id(self) -> str: - """ID of your :func:`begin_analyze_actions` call. - - :return: ID of your :func:`begin_analyze_actions` call. - :rtype: str - """ - return self.polling_method().id - - @classmethod - def from_continuation_token( # type: ignore - cls, - polling_method: AsyncAnalyzeActionsLROPollingMethod, - continuation_token: str, - **kwargs: Any - ) -> "AsyncAnalyzeActionsLROPoller": # type: ignore - """ - :meta private: - """ - client, initial_response, deserialization_callback = polling_method.from_continuation_token( - continuation_token, **kwargs - ) - polling_method._lro_algorithms = [ # pylint: disable=protected-access - TextAnalyticsOperationResourcePolling( - show_stats=initial_response.context.options["show_stats"] - ) - ] - return cls( - client, - initial_response, - functools.partial(deserialization_callback, initial_response), - polling_method # type: ignore - ) - - -class AsyncTextAnalyticsLROPoller(AsyncLROPoller[PollingReturnType]): - def polling_method(self) -> AsyncAnalyzeActionsLROPollingMethod: # type: ignore - """Return the polling method associated to this poller.""" - return self._polling_method # type: ignore - - @property - def details(self) -> MutableMapping[str, Any]: + def details(self) -> Mapping[str, Any]: return { "id": self.polling_method().id, "created_on": self.polling_method().created_on, "expires_on": self.polling_method().expires_on, "display_name": self.polling_method().display_name, "last_modified_on": self.polling_method().last_modified_on, + "actions_failed_count": self.polling_method().actions_failed_count, + "actions_in_progress_count": self.polling_method().actions_in_progress_count, + "actions_succeeded_count": self.polling_method().actions_succeeded_count, + "total_actions_count": self.polling_method().total_actions_count, } + def __getattr__(self, item): + attrs = [ + "created_on", + "expires_on", + "display_name", + "actions_failed_count", + "actions_in_progress_count", + "actions_succeeded_count", + "total_actions_count", + "last_modified_on", + "id" + ] + if item in attrs: + return self.details[item] + return self.__getattribute__(item) + @classmethod def from_continuation_token( # type: ignore cls, polling_method: AsyncAnalyzeActionsLROPollingMethod, continuation_token: str, **kwargs: Any - ) -> "AsyncTextAnalyticsLROPoller": # type: ignore + ) -> "AsyncAnalyzeActionsLROPoller": # type: ignore """ :meta private: """ diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py index 94211266f5b6..b889076d6377 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py @@ -58,14 +58,14 @@ AsyncAnalyzeActionsLROPollingMethod, AsyncAnalyzeHealthcareEntitiesLROPoller, AsyncAnalyzeActionsLROPoller, - AsyncTextAnalyticsLROPoller, + AsyncTextAnalysisLROPoller, ) if TYPE_CHECKING: from azure.core.credentials_async import AsyncTokenCredential -AsyncAnalyzeActionsResponse = AsyncAnalyzeActionsLROPoller[ +AsyncAnalyzeActionsResponse = AsyncTextAnalysisLROPoller[ AsyncItemPaged[ List[ Union[ @@ -1058,7 +1058,7 @@ async def begin_analyze_actions( ] ], **kwargs: Any, - ) -> AsyncAnalyzeActionsLROPoller[ + ) -> AsyncTextAnalysisLROPoller[ AsyncItemPaged[ List[ Union[ @@ -1112,7 +1112,7 @@ async def begin_analyze_actions( Call `continuation_token()` on the poller object to save the long-running operation (LRO) state into an opaque token. Pass the value as the `continuation_token` keyword argument to restart the LRO from a saved state. - :return: An instance of an AsyncAnalyzeActionsLROPoller. Call `result()` on the poller + :return: An instance of an AsyncTextAnalysisLROPoller. Call `result()` on the poller object to return a pageable heterogeneous list of lists. This list of lists is first ordered by the documents you input, then ordered by the actions you input. For example, if you have documents input ["Hello", "world"], and actions @@ -1124,7 +1124,7 @@ async def begin_analyze_actions( Then, you will get the :class:`~azure.ai.textanalytics.RecognizeEntitiesResult` and :class:`~azure.ai.textanalytics.AnalyzeSentimentResult` of "world". :rtype: - ~azure.ai.textanalytics.aio.AsyncAnalyzeActionsLROPoller[~azure.core.async_paging.AsyncItemPaged[ + ~azure.ai.textanalytics.aio.AsyncTextAnalysisLROPoller[~azure.core.async_paging.AsyncItemPaged[ list[RecognizeEntitiesResult or RecognizeLinkedEntitiesResult or RecognizePiiEntitiesResult or ExtractKeyPhrasesResult or AnalyzeSentimentResult or RecognizeCustomEntitiesResult or ClassifyDocumentResult or AnalyzeHealthcareEntitiesResult or DocumentError]]] @@ -1156,7 +1156,6 @@ async def begin_analyze_actions( show_stats = kwargs.pop("show_stats", None) polling_interval = kwargs.pop("polling_interval", 5) continuation_token = kwargs.pop("continuation_token", None) - poller_cls = kwargs.pop("poller_cls", AsyncAnalyzeActionsLROPoller) bespoke = kwargs.pop("bespoke", False) if continuation_token: @@ -1229,7 +1228,6 @@ async def begin_analyze_actions( **kwargs ), continuation_token=continuation_token, - poller_cls=poller_cls, **kwargs ) ) @@ -1284,7 +1282,6 @@ async def begin_analyze_actions( except HttpResponseError as error: return process_http_response_error(error) - @distributed_trace_async @validate_multiapi_args( version_method_added="2022-05-01" @@ -1295,7 +1292,7 @@ async def begin_recognize_custom_entities( project_name: str, deployment_name: str, **kwargs: Any, - ) -> AsyncTextAnalyticsLROPoller[AsyncItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]]: + ) -> AsyncTextAnalysisLROPoller[AsyncItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]]: """Start a long-running custom named entity recognition operation. For information on regional support of custom features and how to train a model to @@ -1335,12 +1332,12 @@ async def begin_recognize_custom_entities( state into an opaque token. Pass the value as the `continuation_token` keyword argument to restart the LRO from a saved state. :keyword str display_name: An optional display name to set for the requested analysis. - :return: An instance of an AsyncTextAnalyticsLROPoller. Call `result()` on the this + :return: An instance of an AsyncTextAnalysisLROPoller. Call `result()` on the this object to return a heterogeneous pageable of :class:`~azure.ai.textanalytics.RecognizeCustomEntitiesResult` and :class:`~azure.ai.textanalytics.DocumentError`. :rtype: - ~azure.ai.textanalytics.aio.AsyncTextAnalyticsLROPoller[~azure.core.async_paging.AsyncItemPaged[ + ~azure.ai.textanalytics.aio.AsyncTextAnalysisLROPoller[~azure.core.async_paging.AsyncItemPaged[ ~azure.ai.textanalytics.RecognizeCustomEntitiesResult or ~azure.ai.textanalytics.DocumentError]] :raises ~azure.core.exceptions.HttpResponseError: @@ -1364,11 +1361,11 @@ async def begin_recognize_custom_entities( if continuation_token: return cast( - AsyncTextAnalyticsLROPoller[AsyncItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]], + AsyncTextAnalysisLROPoller[AsyncItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]]], _get_result_from_continuation_token( self._client._client, # pylint: disable=protected-access continuation_token, - AsyncTextAnalyticsLROPoller, + AsyncAnalyzeActionsLROPoller, AsyncAnalyzeActionsLROPollingMethod( timeout=polling_interval, **kwargs @@ -1380,7 +1377,7 @@ async def begin_recognize_custom_entities( try: return cast( - AsyncTextAnalyticsLROPoller[ + AsyncTextAnalysisLROPoller[ AsyncItemPaged[Union[RecognizeCustomEntitiesResult, DocumentError]] ], await self.begin_analyze_actions( @@ -1394,7 +1391,6 @@ async def begin_recognize_custom_entities( ) ], polling_interval=polling_interval, - poller_cls=AsyncTextAnalyticsLROPoller, bespoke=True, **kwargs ) @@ -1413,7 +1409,7 @@ async def begin_single_label_classify( project_name: str, deployment_name: str, **kwargs: Any, - ) -> AsyncTextAnalyticsLROPoller[AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]]]: + ) -> AsyncTextAnalysisLROPoller[AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]]]: """Start a long-running custom single label classification operation. For information on regional support of custom features and how to train a model to @@ -1449,12 +1445,12 @@ async def begin_single_label_classify( state into an opaque token. Pass the value as the `continuation_token` keyword argument to restart the LRO from a saved state. :keyword str display_name: An optional display name to set for the requested analysis. - :return: An instance of an AsyncTextAnalyticsLROPoller. Call `result()` on the this + :return: An instance of an AsyncTextAnalysisLROPoller. Call `result()` on the this object to return a heterogeneous pageable of :class:`~azure.ai.textanalytics.ClassifyDocumentResult` and :class:`~azure.ai.textanalytics.DocumentError`. :rtype: - ~azure.ai.textanalytics.aio.AsyncTextAnalyticsLROPoller[~azure.core.async_paging.AsyncItemPaged[ + ~azure.ai.textanalytics.aio.AsyncTextAnalysisLROPoller[~azure.core.async_paging.AsyncItemPaged[ ~azure.ai.textanalytics.ClassifyDocumentResult or ~azure.ai.textanalytics.DocumentError]] :raises ~azure.core.exceptions.HttpResponseError: @@ -1477,11 +1473,11 @@ async def begin_single_label_classify( if continuation_token: return cast( - AsyncTextAnalyticsLROPoller[AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]]], + AsyncTextAnalysisLROPoller[AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]]], _get_result_from_continuation_token( self._client._client, # pylint: disable=protected-access continuation_token, - AsyncTextAnalyticsLROPoller, + AsyncAnalyzeActionsLROPoller, AsyncAnalyzeActionsLROPollingMethod( timeout=polling_interval, **kwargs @@ -1493,7 +1489,7 @@ async def begin_single_label_classify( try: return cast( - AsyncTextAnalyticsLROPoller[ + AsyncTextAnalysisLROPoller[ AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]] ], await self.begin_analyze_actions( @@ -1506,7 +1502,6 @@ async def begin_single_label_classify( ) ], polling_interval=polling_interval, - poller_cls=AsyncTextAnalyticsLROPoller, bespoke=True, **kwargs ) diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text.py index 81c13b255571..df9920e65f3d 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text.py @@ -12,7 +12,7 @@ from devtools_testutils import recorded_by_proxy, set_bodiless_matcher from azure.ai.textanalytics import ( TextAnalyticsClient, - TextAnalyticsLROPoller + TextAnalysisLROPoller ) # pre-apply the client_cls positional argument so it needn't be explicitly passed below @@ -60,7 +60,7 @@ def test_poller_metadata( ) poller.result() - assert isinstance(poller, TextAnalyticsLROPoller) + assert isinstance(poller, TextAnalysisLROPoller) assert isinstance(poller.details["created_on"], datetime.datetime) assert isinstance(poller.details["expires_on"], datetime.datetime) assert isinstance(poller.details["last_modified_on"], datetime.datetime) @@ -93,7 +93,7 @@ def test_recognize_custom_entities( polling_interval=self._interval(), ) - assert isinstance(poller, TextAnalyticsLROPoller) + assert isinstance(poller, TextAnalysisLROPoller) document_results = list(poller.result()) for result in document_results: @@ -139,7 +139,7 @@ def test_recognize_custom_entities_continuation_token( None, None, None, continuation_token=continuation_token ) - assert isinstance(poller, TextAnalyticsLROPoller) + assert isinstance(poller, TextAnalysisLROPoller) document_results = list(poller.result()) for result in document_results: @@ -220,7 +220,7 @@ def test_single_label_classify_cont_token( None, None, None, continuation_token=continuation_token ) - assert isinstance(poller, TextAnalyticsLROPoller) + assert isinstance(poller, TextAnalysisLROPoller) document_results = list(poller.result()) for result in document_results: diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text_async.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text_async.py index eff424239c17..38e6c350ae53 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text_async.py @@ -12,7 +12,7 @@ from testcase import TextAnalyticsClientPreparer as _TextAnalyticsClientPreparer from devtools_testutils import set_bodiless_matcher from devtools_testutils.aio import recorded_by_proxy_async -from azure.ai.textanalytics.aio import TextAnalyticsClient, AsyncTextAnalyticsLROPoller +from azure.ai.textanalytics.aio import TextAnalyticsClient, AsyncTextAnalysisLROPoller # pre-apply the client_cls positional argument so it needn't be explicitly passed below TextAnalyticsClientPreparer = functools.partial(_TextAnalyticsClientPreparer, TextAnalyticsClient) @@ -60,7 +60,7 @@ async def test_poller_metadata( ) await poller.result() - assert isinstance(poller, AsyncTextAnalyticsLROPoller) + assert isinstance(poller, AsyncTextAnalysisLROPoller) assert isinstance(poller.details["created_on"], datetime.datetime) assert isinstance(poller.details["expires_on"], datetime.datetime) assert isinstance(poller.details["last_modified_on"], datetime.datetime) @@ -93,7 +93,7 @@ async def test_recognize_custom_entities( polling_interval=self._interval(), ) - assert isinstance(poller, AsyncTextAnalyticsLROPoller) + assert isinstance(poller, AsyncTextAnalysisLROPoller) document_results = await poller.result() async for result in document_results: @@ -139,7 +139,7 @@ async def test_recognize_custom_entities_continuation_token( None, None, None, continuation_token=continuation_token ) - assert isinstance(poller, AsyncTextAnalyticsLROPoller) + assert isinstance(poller, AsyncTextAnalysisLROPoller) document_results = await poller.result() async for result in document_results: @@ -220,7 +220,7 @@ async def test_single_label_classify_cont_token( None, None, None, continuation_token=continuation_token ) - assert isinstance(poller, AsyncTextAnalyticsLROPoller) + assert isinstance(poller, AsyncTextAnalysisLROPoller) document_results = await poller.result() async for result in document_results: From 742abdc6d3ff9b2cb2ca0252c2b9a05d0fa9cb6b Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 18 Jul 2022 15:25:11 -0700 Subject: [PATCH 2/4] pinned version of pylint doesn't understand protocols --- .../azure/ai/textanalytics/_lro.py | 16 ++++++++-------- .../azure/ai/textanalytics/aio/_lro_async.py | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py index 3a3623c3b4c6..858e3eb9c670 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py @@ -37,28 +37,28 @@ class TextAnalysisLROPoller(Protocol[PollingReturnType]): def details(self) -> Mapping[str, Any]: ... - def polling_method(self) -> PollingMethod[PollingReturnType]: + def polling_method(self) -> PollingMethod[PollingReturnType]: # pylint: disable=no-self-use ... - def continuation_token(self) -> str: + def continuation_token(self) -> str: # pylint: disable=no-self-use ... - def status(self) -> str: + def status(self) -> str: # pylint: disable=no-self-use ... - def result(self, timeout: Optional[int] = None) -> PollingReturnType: + def result(self, timeout: Optional[int] = None) -> PollingReturnType: # pylint: disable=no-self-use ... - def wait(self, timeout: Optional[float] = None) -> None: + def wait(self, timeout: Optional[float] = None) -> None: # pylint: disable=no-self-use ... - def done(self) -> bool: + def done(self) -> bool: # pylint: disable=no-self-use ... - def add_done_callback(self, func: Callable) -> None: + def add_done_callback(self, func: Callable) -> None: # pylint: disable=no-self-use, unused-argument ... - def remove_done_callback(self, func: Callable) -> None: + def remove_done_callback(self, func: Callable) -> None: # pylint: disable=no-self-use, unused-argument ... diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_lro_async.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_lro_async.py index 1bdb46527f07..a7be2aaab09e 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_lro_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_lro_async.py @@ -32,13 +32,13 @@ class AsyncTextAnalysisLROPoller(Protocol[PollingReturnType], Awaitable): def details(self) -> Mapping[str, Any]: ... - def polling_method(self) -> AsyncPollingMethod[PollingReturnType]: + def polling_method(self) -> AsyncPollingMethod[PollingReturnType]: # pylint: disable=no-self-use ... - def continuation_token(self) -> str: + def continuation_token(self) -> str: # pylint: disable=no-self-use ... - def status(self) -> str: + def status(self) -> str: # pylint: disable=no-self-use ... async def result(self) -> PollingReturnType: @@ -47,7 +47,7 @@ async def result(self) -> PollingReturnType: async def wait(self) -> None: ... - def done(self) -> bool: + def done(self) -> bool: # pylint: disable=no-self-use ... def __await__(self) -> Generator[Any, None, PollingReturnType]: From fdae7f695255b4cd582d8b9ace259b0c232ed3ad Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 18 Jul 2022 16:05:04 -0700 Subject: [PATCH 3/4] change type hints for multi classification --- .../azure/ai/textanalytics/_lro.py | 4 ++-- .../ai/textanalytics/_text_analytics_client.py | 13 ++++++------- .../aio/_text_analytics_client_async.py | 13 ++++++------- .../tests/test_custom_text.py | 2 +- .../tests/test_custom_text_async.py | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py index 858e3eb9c670..5114907c2b76 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_lro.py @@ -46,10 +46,10 @@ def continuation_token(self) -> str: # pylint: disable=no-self-use def status(self) -> str: # pylint: disable=no-self-use ... - def result(self, timeout: Optional[int] = None) -> PollingReturnType: # pylint: disable=no-self-use + def result(self, timeout: Optional[int] = None) -> PollingReturnType: # pylint: disable=no-self-use, unused-argument ... - def wait(self, timeout: Optional[float] = None) -> None: # pylint: disable=no-self-use + def wait(self, timeout: Optional[float] = None) -> None: # pylint: disable=no-self-use, unused-argument ... def done(self) -> bool: # pylint: disable=no-self-use diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py index 59ec08979cf7..307618323a56 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py @@ -1523,7 +1523,7 @@ def begin_multi_label_classify( project_name, deployment_name, **kwargs: Any, - ) -> TextAnalyticsLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]]: + ) -> TextAnalysisLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]]: """Start a long-running custom multi label classification operation. For information on regional support of custom features and how to train a model to @@ -1559,12 +1559,12 @@ def begin_multi_label_classify( state into an opaque token. Pass the value as the `continuation_token` keyword argument to restart the LRO from a saved state. :keyword str display_name: An optional display name to set for the requested analysis. - :return: An instance of an TextAnalyticsLROPoller. Call `result()` on the this + :return: An instance of an TextAnalysisLROPoller. Call `result()` on the this object to return a heterogeneous pageable of :class:`~azure.ai.textanalytics.ClassifyDocumentResult` and :class:`~azure.ai.textanalytics.DocumentError`. :rtype: - ~azure.ai.textanalytics.TextAnalyticsLROPoller[~azure.core.paging.ItemPaged[ + ~azure.ai.textanalytics.TextAnalysisLROPoller[~azure.core.paging.ItemPaged[ ~azure.ai.textanalytics.ClassifyDocumentResult or ~azure.ai.textanalytics.DocumentError]] :raises ~azure.core.exceptions.HttpResponseError: @@ -1587,11 +1587,11 @@ def begin_multi_label_classify( if continuation_token: return cast( - TextAnalyticsLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]], + TextAnalysisLROPoller[ItemPaged[Union[ClassifyDocumentResult, DocumentError]]], _get_result_from_continuation_token( self._client._client, # pylint: disable=protected-access continuation_token, - TextAnalyticsLROPoller, + AnalyzeActionsLROPoller, AnalyzeActionsLROPollingMethod( timeout=polling_interval, **kwargs @@ -1603,7 +1603,7 @@ def begin_multi_label_classify( try: return cast( - TextAnalyticsLROPoller[ + TextAnalysisLROPoller[ ItemPaged[Union[ClassifyDocumentResult, DocumentError]] ], self.begin_analyze_actions( @@ -1616,7 +1616,6 @@ def begin_multi_label_classify( ) ], polling_interval=polling_interval, - poller_cls=TextAnalyticsLROPoller, bespoke=True, **kwargs ) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py index 4117d3bdd7a7..fecdcd396423 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_text_analytics_client_async.py @@ -1520,7 +1520,7 @@ async def begin_multi_label_classify( project_name: str, deployment_name: str, **kwargs: Any, - ) -> AsyncTextAnalyticsLROPoller[AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]]]: + ) -> AsyncTextAnalysisLROPoller[AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]]]: """Start a long-running custom multi label classification operation. For information on regional support of custom features and how to train a model to @@ -1556,12 +1556,12 @@ async def begin_multi_label_classify( state into an opaque token. Pass the value as the `continuation_token` keyword argument to restart the LRO from a saved state. :keyword str display_name: An optional display name to set for the requested analysis. - :return: An instance of an AsyncTextAnalyticsLROPoller. Call `result()` on the this + :return: An instance of an AsyncTextAnalysisLROPoller. Call `result()` on the this object to return a heterogeneous pageable of :class:`~azure.ai.textanalytics.ClassifyDocumentResult` and :class:`~azure.ai.textanalytics.DocumentError`. :rtype: - ~azure.ai.textanalytics.aio.AsyncTextAnalyticsLROPoller[~azure.core.async_paging.AsyncItemPaged[ + ~azure.ai.textanalytics.aio.AsyncTextAnalysisLROPoller[~azure.core.async_paging.AsyncItemPaged[ ~azure.ai.textanalytics.ClassifyDocumentResult or ~azure.ai.textanalytics.DocumentError]] :raises ~azure.core.exceptions.HttpResponseError: @@ -1584,11 +1584,11 @@ async def begin_multi_label_classify( if continuation_token: return cast( - AsyncTextAnalyticsLROPoller[AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]]], + AsyncTextAnalysisLROPoller[AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]]], _get_result_from_continuation_token( self._client._client, # pylint: disable=protected-access continuation_token, - AsyncTextAnalyticsLROPoller, + AsyncAnalyzeActionsLROPoller, AsyncAnalyzeActionsLROPollingMethod( timeout=polling_interval, **kwargs @@ -1600,7 +1600,7 @@ async def begin_multi_label_classify( try: return cast( - AsyncTextAnalyticsLROPoller[ + AsyncTextAnalysisLROPoller[ AsyncItemPaged[Union[ClassifyDocumentResult, DocumentError]] ], await self.begin_analyze_actions( @@ -1613,7 +1613,6 @@ async def begin_multi_label_classify( ) ], polling_interval=polling_interval, - poller_cls=AsyncTextAnalyticsLROPoller, bespoke=True, **kwargs ) diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text.py index 3382a6f2a3cf..45e73504c50e 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text.py @@ -302,7 +302,7 @@ def test_multi_label_classify_cont_token( None, None, None, continuation_token=continuation_token ) - assert isinstance(poller, TextAnalyticsLROPoller) + assert isinstance(poller, TextAnalysisLROPoller) document_results = list(poller.result()) for result in document_results: diff --git a/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text_async.py b/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text_async.py index 87317cbef667..6c724d9053b7 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/tests/test_custom_text_async.py @@ -303,7 +303,7 @@ async def test_multi_label_classify_cont_token( None, None, None, continuation_token=continuation_token ) - assert isinstance(poller, AsyncTextAnalyticsLROPoller) + assert isinstance(poller, AsyncTextAnalysisLROPoller) document_results = await poller.result() async for result in document_results: From 2282dffbd10c1efe2ba4162b535612e9b7f30dc2 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 18 Jul 2022 16:23:08 -0700 Subject: [PATCH 4/4] update changelog --- sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md b/sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md index 3628af1c7bec..73b7f4e25345 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md +++ b/sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md @@ -7,6 +7,8 @@ - Added `begin_recognize_custom_entities` client method to recognize custom named entities in documents. - Added `begin_single_label_classify` client method to perform custom single label classification on documents. - Added `begin_multi_label_classify` client method to perform custom multi label classification on documents. +- Added property `details` on returned poller objects which contain long-running operation metadata. +- Added `TextAnalysisLROPoller` and `AsyncTextAnalysisLROPoller` protocols to describe the return types from long-running operations. ### Breaking Changes