Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[textanalytics] run black #19590

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,46 +49,46 @@
EntityConditionality,
EntityCertainty,
EntityAssociation,
HealthcareEntityCategory
HealthcareEntityCategory,
)

from ._lro import AnalyzeHealthcareEntitiesLROPoller, AnalyzeActionsLROPoller

__all__ = [
'TextAnalyticsApiVersion',
'TextAnalyticsClient',
'DetectLanguageInput',
'TextDocumentInput',
'DetectedLanguage',
'RecognizeEntitiesResult',
'DetectLanguageResult',
'CategorizedEntity',
'TextAnalyticsError',
'TextAnalyticsWarning',
'ExtractKeyPhrasesResult',
'RecognizeLinkedEntitiesResult',
'AnalyzeSentimentResult',
'TextDocumentStatistics',
'DocumentError',
'LinkedEntity',
'LinkedEntityMatch',
'TextDocumentBatchStatistics',
'SentenceSentiment',
'SentimentConfidenceScores',
'MinedOpinion',
'TargetSentiment',
'AssessmentSentiment',
'RecognizePiiEntitiesResult',
'PiiEntity',
'PiiEntityDomain',
'AnalyzeHealthcareEntitiesResult',
'HealthcareEntity',
'HealthcareEntityDataSource',
'RecognizeEntitiesAction',
'RecognizeLinkedEntitiesAction',
'RecognizePiiEntitiesAction',
'ExtractKeyPhrasesAction',
'_AnalyzeActionsType',
"TextAnalyticsApiVersion",
"TextAnalyticsClient",
"DetectLanguageInput",
"TextDocumentInput",
"DetectedLanguage",
"RecognizeEntitiesResult",
"DetectLanguageResult",
"CategorizedEntity",
"TextAnalyticsError",
"TextAnalyticsWarning",
"ExtractKeyPhrasesResult",
"RecognizeLinkedEntitiesResult",
"AnalyzeSentimentResult",
"TextDocumentStatistics",
"DocumentError",
"LinkedEntity",
"LinkedEntityMatch",
"TextDocumentBatchStatistics",
"SentenceSentiment",
"SentimentConfidenceScores",
"MinedOpinion",
"TargetSentiment",
"AssessmentSentiment",
"RecognizePiiEntitiesResult",
"PiiEntity",
"PiiEntityDomain",
"AnalyzeHealthcareEntitiesResult",
"HealthcareEntity",
"HealthcareEntityDataSource",
"RecognizeEntitiesAction",
"RecognizeLinkedEntitiesAction",
"RecognizePiiEntitiesAction",
"ExtractKeyPhrasesAction",
"_AnalyzeActionsType",
"PiiEntityCategory",
"HealthcareEntityRelation",
"HealthcareRelation",
Expand All @@ -100,7 +100,7 @@
"AnalyzeSentimentAction",
"AnalyzeHealthcareEntitiesLROPoller",
"AnalyzeActionsLROPoller",
"HealthcareEntityCategory"
"HealthcareEntityCategory",
]

__version__ = VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
from ._policies import TextAnalyticsResponseHookPolicy
from ._user_agent import USER_AGENT


class TextAnalyticsApiVersion(str, Enum):
"""Text Analytics API versions supported by this package"""

#: this is the default version
V3_1 = "v3.1"
V3_0 = "v3.0"


def _authentication_policy(credential):
authentication_policy = None
if credential is None:
Expand All @@ -26,8 +28,10 @@ def _authentication_policy(credential):
name="Ocp-Apim-Subscription-Key", credential=credential
)
elif credential is not None and not hasattr(credential, "get_token"):
raise TypeError("Unsupported credential: {}. Use an instance of AzureKeyCredential "
"or a token credential from azure.identity".format(type(credential)))
raise TypeError(
"Unsupported credential: {}. Use an instance of AzureKeyCredential "
"or a token credential from azure.identity".format(type(credential))
)
return authentication_policy


Expand All @@ -43,7 +47,6 @@ def __init__(self, endpoint, credential, **kwargs):
**kwargs
)


def __enter__(self):
self._client.__enter__() # pylint:disable=no-member
return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
from azure.core.polling._poller import PollingReturnType
from azure.core.exceptions import HttpResponseError
from azure.core.polling import LROPoller
from azure.core.polling.base_polling import LROBasePolling, OperationResourcePolling, OperationFailed, BadStatus
from azure.core.polling.base_polling import (
LROBasePolling,
OperationResourcePolling,
OperationFailed,
BadStatus,
)

_FINISHED = frozenset(["succeeded", "cancelled", "failed", "partiallycompleted"])
_FAILED = frozenset(["failed"])
Expand All @@ -20,19 +25,24 @@


class TextAnalyticsOperationResourcePolling(OperationResourcePolling):
def __init__(self, operation_location_header="operation-location", show_stats=False):
super(TextAnalyticsOperationResourcePolling, self).__init__(operation_location_header=operation_location_header)
def __init__(
self, operation_location_header="operation-location", show_stats=False
):
super(TextAnalyticsOperationResourcePolling, self).__init__(
operation_location_header=operation_location_header
)
self._show_stats = show_stats
self._query_params = {
"showStats": show_stats
}
self._query_params = {"showStats": show_stats}

def get_polling_url(self):
if not self._show_stats:
return super(TextAnalyticsOperationResourcePolling, self).get_polling_url()

return super(TextAnalyticsOperationResourcePolling, self).get_polling_url() + \
"?" + urlencode(self._query_params)
return (
super(TextAnalyticsOperationResourcePolling, self).get_polling_url()
+ "?"
+ urlencode(self._query_params)
)


class TextAnalyticsLROPollingMethod(LROBasePolling):
Expand Down Expand Up @@ -93,18 +103,20 @@ def _poll(self):
final_get_url = self._operation.get_final_get_url(self._pipeline_response)
if final_get_url:
self._pipeline_response = self.request_status(final_get_url)
TextAnalyticsLROPollingMethod._raise_if_bad_http_status_and_method(self._pipeline_response.http_response)
TextAnalyticsLROPollingMethod._raise_if_bad_http_status_and_method(
self._pipeline_response.http_response
)


class AnalyzeHealthcareEntitiesLROPollingMethod(TextAnalyticsLROPollingMethod):

def __init__(self, *args, **kwargs):
self._text_analytics_client = kwargs.pop("text_analytics_client")
super(AnalyzeHealthcareEntitiesLROPollingMethod, self).__init__(*args, **kwargs)

@property
def _current_body(self):
from ._generated.v3_1.models import JobMetadata

return JobMetadata.deserialize(self._pipeline_response)

@property
Expand Down Expand Up @@ -133,11 +145,9 @@ def id(self):


class AnalyzeHealthcareEntitiesLROPoller(LROPoller, Generic[PollingReturnType]):

def polling_method(self):
# type: () -> AnalyzeHealthcareEntitiesLROPollingMethod
"""Return the polling method associated to this poller.
"""
"""Return the polling method associated to this poller."""
return self._polling_method # type: ignore

@property
Expand Down Expand Up @@ -208,20 +218,23 @@ def cancel(self, **kwargs): # type: ignore
# Get a final status update.
getattr(self._polling_method, "update_status")()

return getattr(self._polling_method, "_text_analytics_client").begin_cancel_health_job(
self.id,
polling=TextAnalyticsLROPollingMethod(timeout=polling_interval)
return getattr(
self._polling_method, "_text_analytics_client"
).begin_cancel_health_job(
self.id, polling=TextAnalyticsLROPollingMethod(timeout=polling_interval)
)

except HttpResponseError as error:
from ._response_handlers import process_http_response_error

process_http_response_error(error)

class AnalyzeActionsLROPollingMethod(TextAnalyticsLROPollingMethod):

class AnalyzeActionsLROPollingMethod(TextAnalyticsLROPollingMethod):
@property
def _current_body(self):
from ._generated.v3_1.models import AnalyzeJobMetadata

return AnalyzeJobMetadata.deserialize(self._pipeline_response)

@property
Expand All @@ -246,19 +259,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["tasks"]["failed"]

@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["tasks"]["inProgress"]

@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["tasks"]["completed"]

@property
def last_modified_on(self):
Expand All @@ -270,7 +283,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["tasks"]["total"]

@property
def id(self):
Expand All @@ -280,11 +293,9 @@ def id(self):


class AnalyzeActionsLROPoller(LROPoller, Generic[PollingReturnType]):

def polling_method(self):
# type: () -> AnalyzeActionsLROPollingMethod
"""Return the polling method associated to this poller.
"""
"""Return the polling method associated to this poller."""
return self._polling_method # type: ignore

@property
Expand Down
Loading