From df695ac25a530c09054360669408fdcd50aa24a9 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Wed, 27 Jan 2021 09:03:29 -0800 Subject: [PATCH 1/2] unexpose api_version property --- .../ai/formrecognizer/_form_base_client.py | 10 +++++----- .../formrecognizer/_form_recognizer_client.py | 12 +++++------ .../formrecognizer/_form_training_client.py | 20 +++++++++---------- .../aio/_form_base_client_async.py | 10 +++++----- .../aio/_form_recognizer_client_async.py | 12 +++++------ .../aio/_form_training_client_async.py | 20 +++++++++---------- .../tests/test_training.py | 8 ++++---- .../tests/test_training_async.py | 8 ++++---- 8 files changed, 50 insertions(+), 50 deletions(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_base_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_base_client.py index efd8e1737f2d..db3407a469ea 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_base_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_base_client.py @@ -24,8 +24,8 @@ def __init__(self, endpoint, credential, **kwargs): # type: (str, Union[AzureKeyCredential, TokenCredential], Any) -> None self._endpoint = endpoint self._credential = credential - self.api_version = kwargs.pop('api_version', FormRecognizerApiVersion.V2_1_PREVIEW) - validate_api_version(self.api_version) + self._api_version = kwargs.pop('api_version', FormRecognizerApiVersion.V2_1_PREVIEW) + validate_api_version(self._api_version) authentication_policy = get_authentication_policy(credential) polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL) @@ -57,12 +57,12 @@ def __init__(self, endpoint, credential, **kwargs): self._client = FormRecognizer( endpoint=endpoint, credential=credential, # type: ignore - api_version=self.api_version, + api_version=self._api_version, sdk_moniker=USER_AGENT, authentication_policy=authentication_policy, http_logging_policy=http_logging_policy, polling_interval=polling_interval, **kwargs ) - self._deserialize = _get_deserialize(self.api_version) - self._generated_models = self._client.models(self.api_version) + self._deserialize = _get_deserialize(self._api_version) + self._generated_models = self._client.models(self._api_version) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py index 64efc28f7e62..865499923ffd 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_recognizer_client.py @@ -122,7 +122,7 @@ def begin_recognize_receipts(self, receipt, **kwargs): # FIXME: part of this code will be removed once autorest can handle diff mixin # signatures across API versions if locale: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"locale": locale}) else: raise ValueError("'locale' is only available for API version V2_1_PREVIEW and up") @@ -179,7 +179,7 @@ def begin_recognize_receipts_from_url(self, receipt_url, **kwargs): # FIXME: part of this code will be removed once autorest can handle diff mixin # signatures across API versions if locale: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"locale": locale}) else: raise ValueError("'locale' is only available for API version V2_1_PREVIEW and up") @@ -488,13 +488,13 @@ def begin_recognize_content(self, form, **kwargs): # FIXME: part of this code will be removed once autorest can handle diff mixin # signatures across API versions if pages: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"pages": pages}) else: raise ValueError("'pages' is only available for API version V2_1_PREVIEW and up") if language: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"language": language}) else: raise ValueError("'language' is only available for API version V2_1_PREVIEW and up") @@ -541,13 +541,13 @@ def begin_recognize_content_from_url(self, form_url, **kwargs): # FIXME: part of this code will be removed once autorest can handle diff mixin # signatures across API versions if pages: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"pages": pages}) else: raise ValueError("'pages' is only available for API version V2_1_PREVIEW and up") if language: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"language": language}) else: raise ValueError("'language' is only available for API version V2_1_PREVIEW and up") diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py index 8af95b38cc1c..b2e616e5a270 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/_form_training_client.py @@ -123,20 +123,20 @@ def begin_training(self, training_files_url, use_training_labels, **kwargs): def callback_v2_0(raw_response): model = self._deserialize(self._generated_models.Model, raw_response) - return CustomFormModel._from_generated(model, api_version=self.api_version) + return CustomFormModel._from_generated(model, api_version=self._api_version) def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument model = self._deserialize(self._generated_models.Model, raw_response) - return CustomFormModel._from_generated(model, api_version=self.api_version) + return CustomFormModel._from_generated(model, api_version=self._api_version) cls = kwargs.pop("cls", None) model_name = kwargs.pop("model_name", None) - if model_name and self.api_version == "2.0": + if model_name and self._api_version == "2.0": raise ValueError("'model_name' is only available for API version V2_1_PREVIEW and up") continuation_token = kwargs.pop("continuation_token", None) polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - if self.api_version == "2.0": + if self._api_version == "2.0": deserialization_callback = cls if cls else callback_v2_0 if continuation_token: return LROPoller.from_continuation_token( @@ -232,7 +232,7 @@ def list_custom_models(self, **kwargs): """ return self._client.list_custom_models( # type: ignore cls=kwargs.pop("cls", lambda objs: - [CustomFormModelInfo._from_generated(x, api_version=self.api_version) for x in objs]), + [CustomFormModelInfo._from_generated(x, api_version=self._api_version) for x in objs]), **kwargs ) @@ -285,7 +285,7 @@ def get_custom_model(self, model_id, **kwargs): response = self._client.get_custom_model(model_id=model_id, include_keys=True, **kwargs) if hasattr(response, "composed_train_results") and response.composed_train_results: return CustomFormModel._from_generated_composed(response) - return CustomFormModel._from_generated(response, api_version=self.api_version) + return CustomFormModel._from_generated(response, api_version=self._api_version) @distributed_trace def get_copy_authorization(self, resource_id, resource_region, **kwargs): @@ -369,12 +369,12 @@ def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument copy_operation = self._deserialize(self._generated_models.CopyOperationResult, raw_response) model_id = copy_operation.copy_result.model_id if hasattr(copy_operation, "copy_result") else None if model_id: - return CustomFormModelInfo._from_generated(copy_operation, model_id, api_version=self.api_version) + return CustomFormModelInfo._from_generated(copy_operation, model_id, api_version=self._api_version) if target: return CustomFormModelInfo._from_generated( - copy_operation, target["model_id"], api_version=self.api_version + copy_operation, target["model_id"], api_version=self._api_version ) - return CustomFormModelInfo._from_generated(copy_operation, None, api_version=self.api_version) + return CustomFormModelInfo._from_generated(copy_operation, None, api_version=self._api_version) return self._client.begin_copy_custom_model( # type: ignore model_id=model_id, @@ -465,7 +465,7 @@ def get_form_recognizer_client(self, **kwargs): endpoint=self._endpoint, credential=self._credential, pipeline=_pipeline, - api_version=self.api_version, + api_version=self._api_version, **kwargs ) # need to share config, but can't pass as a keyword into client diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_base_client_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_base_client_async.py index e427047745ba..c6025ea71c4c 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_base_client_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_base_client_async.py @@ -29,8 +29,8 @@ def __init__( ) -> None: self._endpoint = endpoint self._credential = credential - self.api_version = kwargs.pop('api_version', FormRecognizerApiVersion.V2_1_PREVIEW) - validate_api_version(self.api_version) + self._api_version = kwargs.pop('api_version', FormRecognizerApiVersion.V2_1_PREVIEW) + validate_api_version(self._api_version) authentication_policy = get_authentication_policy(credential) polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL) @@ -57,12 +57,12 @@ def __init__( self._client = FormRecognizer( endpoint=endpoint, credential=credential, # type: ignore - api_version=self.api_version, + api_version=self._api_version, sdk_moniker=USER_AGENT, authentication_policy=authentication_policy, http_logging_policy=http_logging_policy, polling_interval=polling_interval, **kwargs ) - self._deserialize = _get_deserialize(self.api_version) - self._generated_models = self._client.models(self.api_version) + self._deserialize = _get_deserialize(self._api_version) + self._generated_models = self._client.models(self._api_version) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py index 5c186cd5f0ab..7bbad350c039 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_recognizer_client_async.py @@ -122,7 +122,7 @@ async def begin_recognize_receipts( # FIXME: part of this code will be removed once autorest can handle diff mixin # signatures across API versions if locale: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"locale": locale}) else: raise ValueError("'locale' is only available for API version V2_1_PREVIEW and up") @@ -182,7 +182,7 @@ async def begin_recognize_receipts_from_url( # FIXME: part of this code will be removed once autorest can handle diff mixin # signatures across API versions if locale: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"locale": locale}) else: raise ValueError("'locale' is only available for API version V2_1_PREVIEW and up") @@ -490,13 +490,13 @@ async def begin_recognize_content( # FIXME: part of this code will be removed once autorest can handle diff mixin # signatures across API versions if pages: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"pages": pages}) else: raise ValueError("'pages' is only available for API version V2_1_PREVIEW and up") if language: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"language": language}) else: raise ValueError("'language' is only available for API version V2_1_PREVIEW and up") @@ -542,13 +542,13 @@ async def begin_recognize_content_from_url(self, form_url: str, **kwargs: Any) - # FIXME: part of this code will be removed once autorest can handle diff mixin # signatures across API versions if pages: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"pages": pages}) else: raise ValueError("'pages' is only available for API version V2_1_PREVIEW and up") if language: - if self.api_version == FormRecognizerApiVersion.V2_1_PREVIEW: + if self._api_version == FormRecognizerApiVersion.V2_1_PREVIEW: kwargs.update({"language": language}) else: raise ValueError("'language' is only available for API version V2_1_PREVIEW and up") diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py index 9d8714f40071..e4664b44298e 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/azure/ai/formrecognizer/aio/_form_training_client_async.py @@ -125,20 +125,20 @@ async def begin_training( def callback_v2_0(raw_response): model = self._deserialize(self._generated_models.Model, raw_response) - return CustomFormModel._from_generated(model, api_version=self.api_version) + return CustomFormModel._from_generated(model, api_version=self._api_version) def callback_v2_1(raw_response, _, headers): # pylint: disable=unused-argument model = self._deserialize(self._generated_models.Model, raw_response) - return CustomFormModel._from_generated(model, api_version=self.api_version) + return CustomFormModel._from_generated(model, api_version=self._api_version) cls = kwargs.pop("cls", None) model_name = kwargs.pop("model_name", None) - if model_name and self.api_version == "2.0": + if model_name and self._api_version == "2.0": raise ValueError("'model_name' is only available for API version V2_1_PREVIEW and up") continuation_token = kwargs.pop("continuation_token", None) polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) - if self.api_version == "2.0": + if self._api_version == "2.0": deserialization_callback = cls if cls else callback_v2_0 if continuation_token: return AsyncLROPoller.from_continuation_token( @@ -238,7 +238,7 @@ def list_custom_models(self, **kwargs: Any) -> AsyncItemPaged[CustomFormModelInf """ return self._client.list_custom_models( # type: ignore cls=kwargs.pop("cls", lambda objs: - [CustomFormModelInfo._from_generated(x, api_version=self.api_version) for x in objs]), + [CustomFormModelInfo._from_generated(x, api_version=self._api_version) for x in objs]), **kwargs ) @@ -291,7 +291,7 @@ async def get_custom_model(self, model_id: str, **kwargs: Any) -> CustomFormMode ) if hasattr(response, "composed_train_results") and response.composed_train_results: return CustomFormModel._from_generated_composed(response) - return CustomFormModel._from_generated(response, api_version=self.api_version) + return CustomFormModel._from_generated(response, api_version=self._api_version) @distributed_trace_async async def get_copy_authorization( @@ -378,12 +378,12 @@ def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument copy_operation = self._deserialize(self._generated_models.CopyOperationResult, raw_response) model_id = copy_operation.copy_result.model_id if hasattr(copy_operation, "copy_result") else None if model_id: - return CustomFormModelInfo._from_generated(copy_operation, model_id, api_version=self.api_version) + return CustomFormModelInfo._from_generated(copy_operation, model_id, api_version=self._api_version) if target: return CustomFormModelInfo._from_generated( - copy_operation, target["model_id"], api_version=self.api_version + copy_operation, target["model_id"], api_version=self._api_version ) - return CustomFormModelInfo._from_generated(copy_operation, None, api_version=self.api_version) + return CustomFormModelInfo._from_generated(copy_operation, None, api_version=self._api_version) return await self._client.begin_copy_custom_model( # type: ignore model_id=model_id, @@ -476,7 +476,7 @@ def get_form_recognizer_client(self, **kwargs: Any) -> FormRecognizerClient: endpoint=self._endpoint, credential=self._credential, pipeline=_pipeline, - api_version=self.api_version, + api_version=self._api_version, **kwargs ) # need to share config, but can't pass as a keyword into client diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_training.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_training.py index d135a17a5e4c..ab859a9978a6 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_training.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_training.py @@ -109,7 +109,7 @@ def test_training_transform(self, client, container_sas_url): def callback(response, _, headers): raw_model = client._deserialize(Model, response) - custom_model = CustomFormModel._from_generated(raw_model, client.api_version) + custom_model = CustomFormModel._from_generated(raw_model, client._api_version) raw_response.append(raw_model) raw_response.append(custom_model) @@ -128,7 +128,7 @@ def test_training_multipage_transform(self, client, container_sas_url): def callback(response, _, headers): raw_model = client._deserialize(Model, response) - custom_model = CustomFormModel._from_generated(raw_model, client.api_version) + custom_model = CustomFormModel._from_generated(raw_model, client._api_version) raw_response.append(raw_model) raw_response.append(custom_model) @@ -196,7 +196,7 @@ def test_training_with_labels_transform(self, client, container_sas_url): def callback(response, _, headers): raw_model = client._deserialize(Model, response) - custom_model = CustomFormModel._from_generated(raw_model, client.api_version) + custom_model = CustomFormModel._from_generated(raw_model, client._api_version) raw_response.append(raw_model) raw_response.append(custom_model) @@ -215,7 +215,7 @@ def test_train_multipage_w_labels_transform(self, client, container_sas_url): def callback(response, _, headers): raw_model = client._deserialize(Model, response) - custom_model = CustomFormModel._from_generated(raw_model, client.api_version) + custom_model = CustomFormModel._from_generated(raw_model, client._api_version) raw_response.append(raw_model) raw_response.append(custom_model) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_training_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_training_async.py index 05fb633680e0..1bfe2fa5ecff 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_training_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_training_async.py @@ -117,7 +117,7 @@ async def test_training_transform(self, client, container_sas_url): def callback(response, _, headers): raw_model = client._deserialize(Model, response) - custom_model = CustomFormModel._from_generated(raw_model, client.api_version) + custom_model = CustomFormModel._from_generated(raw_model, client._api_version) raw_response.append(raw_model) raw_response.append(custom_model) @@ -140,7 +140,7 @@ async def test_training_multipage_transform(self, client, container_sas_url): def callback(response, _, headers): raw_model = client._deserialize(Model, response) - custom_model = CustomFormModel._from_generated(raw_model, client.api_version) + custom_model = CustomFormModel._from_generated(raw_model, client._api_version) raw_response.append(raw_model) raw_response.append(custom_model) @@ -208,7 +208,7 @@ async def test_training_with_labels_transform(self, client, container_sas_url): def callback(response, _, headers): raw_model = client._deserialize(Model, response) - custom_model = CustomFormModel._from_generated(raw_model, client.api_version) + custom_model = CustomFormModel._from_generated(raw_model, client._api_version) raw_response.append(raw_model) raw_response.append(custom_model) @@ -228,7 +228,7 @@ async def test_train_multipage_w_lbls_trnsfrm(self, client, container_sas_url): def callback(response, _, headers): raw_model = client._deserialize(Model, response) - custom_model = CustomFormModel._from_generated(raw_model, client.api_version) + custom_model = CustomFormModel._from_generated(raw_model, client._api_version) raw_response.append(raw_model) raw_response.append(custom_model) From aa065cce985b2b954ce67fb640abf8c01e45a8c2 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Wed, 27 Jan 2021 09:12:30 -0800 Subject: [PATCH 2/2] update changelog --- sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md index 4f8d734c2995..777ed2d74a9a 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md +++ b/sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md @@ -6,7 +6,8 @@ - `Appearance` is renamed to `TextAppearance` - `Style` is renamed to `TextStyle` - +- Client property `api_version` is no longer exposed. Pass keyword argument `api_version` into the client to select the +API version ## 3.1.0b2 (2021-01-12)