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

[formrecognizer] unexpose api_version property #16378

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we add this to the changelog. sorry this was not a ba

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 good point

validate_api_version(self._api_version)

authentication_policy = get_authentication_policy(credential)
polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand 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")
Expand Down Expand 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")
Expand Down Expand 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand 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")
Expand Down Expand 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")
Expand Down Expand 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down