Skip to content

Commit f8315ad

Browse files
[translation] regen+typing (Azure#27786)
* some typing improvements * regen and rerecord now that we don't gen with maxpagesize anymore * fix typing errs and dependencies * shared reqs * enable samples for pyright/mypy * cspell * fix cspell again * update * update recordings tag * pep526 type hints * regen
1 parent 231c393 commit f8315ad

File tree

58 files changed

+5598
-3449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5598
-3449
lines changed

.vscode/cspell.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,10 @@
430430
]
431431
},
432432
{
433-
"filename": "sdk/translation/azure-ai-translation-document/tests/*.py",
433+
"filename": "sdk/translation/azure-ai-translation-document/**",
434434
"words": [
435-
"essai"
435+
"essai",
436+
"myfoldername"
436437
]
437438
},
438439
{

sdk/translation/azure-ai-translation-document/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/translation/azure-ai-translation-document",
5-
"Tag": "python/translation/azure-ai-translation-document_8e3d5b50cb"
5+
"Tag": "python/translation/azure-ai-translation-document_d8387d1500"
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
1+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ._generated import (
1313
BatchDocumentTranslationClient as _BatchDocumentTranslationClient,
1414
)
15+
from ._generated.models import StartTranslationDetails
1516
from ._models import (
1617
TranslationStatus,
1718
DocumentStatus,
@@ -31,6 +32,7 @@
3132
get_translation_input,
3233
POLLING_INTERVAL,
3334
)
35+
from ._api_version import DocumentTranslationApiVersion
3436
if TYPE_CHECKING:
3537
from azure.core.credentials import TokenCredential
3638

@@ -81,6 +83,7 @@ def __init__(
8183
self._credential = credential
8284
self._api_version = kwargs.pop("api_version", None)
8385
if hasattr(self._api_version, "value"):
86+
self._api_version = cast(DocumentTranslationApiVersion, self._api_version)
8487
self._api_version = self._api_version.value
8588
authentication_policy = get_authentication_policy(credential)
8689
polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)
@@ -276,7 +279,7 @@ def deserialization_callback(
276279
callback = kwargs.pop("cls", deserialization_callback)
277280
return cast(DocumentTranslationLROPoller[ItemPaged[DocumentStatus]],
278281
self._client.document_translation.begin_start_translation(
279-
inputs=inputs if not continuation_token else None,
282+
body=StartTranslationDetails(inputs=inputs),
280283
polling=DocumentTranslationLROPollingMethod(
281284
timeout=polling_interval,
282285
lro_algorithms=[TranslationPolling()],
@@ -398,7 +401,7 @@ def _convert_from_generated_model(
398401
order_by=order_by,
399402
statuses=statuses,
400403
top=top,
401-
skip=skip,
404+
skip=skip, # type: ignore
402405
**kwargs
403406
)
404407
)
@@ -481,7 +484,7 @@ def _convert_from_generated_model(generated_model):
481484
order_by=order_by,
482485
statuses=statuses,
483486
top=top,
484-
skip=skip,
487+
skip=skip, # type: ignore
485488
**kwargs
486489
)
487490
)

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_generated/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
from ._batch_document_translation_client import BatchDocumentTranslationClient
10-
__all__ = ['BatchDocumentTranslationClient']
9+
from ._client import BatchDocumentTranslationClient
1110

1211
try:
13-
from ._patch import patch_sdk # type: ignore
14-
patch_sdk()
12+
from ._patch import __all__ as _patch_all
13+
from ._patch import * # pylint: disable=unused-wildcard-import
1514
except ImportError:
16-
pass
15+
_patch_all = []
16+
from ._patch import patch_sdk as _patch_sdk
17+
18+
__all__ = [
19+
"BatchDocumentTranslationClient",
20+
]
21+
__all__.extend([p for p in _patch_all if p not in __all__])
22+
23+
_patch_sdk()

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_generated/_batch_document_translation_client.py

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from copy import deepcopy
10+
from typing import Any, TYPE_CHECKING
11+
12+
from azure.core import PipelineClient
13+
from azure.core.rest import HttpRequest, HttpResponse
14+
15+
from . import models as _models
16+
from ._configuration import BatchDocumentTranslationClientConfiguration
17+
from ._serialization import Deserializer, Serializer
18+
from .operations import DocumentTranslationOperations
19+
20+
if TYPE_CHECKING:
21+
# pylint: disable=unused-import,ungrouped-imports
22+
from azure.core.credentials import TokenCredential
23+
24+
25+
class BatchDocumentTranslationClient: # pylint: disable=client-accepts-api-version-keyword
26+
"""BatchDocumentTranslationClient.
27+
28+
:ivar document_translation: DocumentTranslationOperations operations
29+
:vartype document_translation:
30+
azure.ai.translation.document.operations.DocumentTranslationOperations
31+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
32+
https://westus.api.cognitive.microsoft.com). Required.
33+
:type endpoint: str
34+
:param credential: Credential needed for the client to connect to Azure. Required.
35+
:type credential: ~azure.core.credentials.TokenCredential
36+
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
37+
Retry-After header is present.
38+
"""
39+
40+
def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
41+
_endpoint = "{endpoint}/translator/text/batch/v1.0"
42+
self._config = BatchDocumentTranslationClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
43+
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
44+
45+
client_models = {k: v for k, v in _models._models.__dict__.items() if isinstance(v, type)}
46+
client_models.update({k: v for k, v in _models.__dict__.items() if isinstance(v, type)})
47+
self._serialize = Serializer(client_models)
48+
self._deserialize = Deserializer(client_models)
49+
self._serialize.client_side_validation = False
50+
self.document_translation = DocumentTranslationOperations(
51+
self._client, self._config, self._serialize, self._deserialize
52+
)
53+
54+
def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
55+
"""Runs the network request through the client's chained policies.
56+
57+
>>> from azure.core.rest import HttpRequest
58+
>>> request = HttpRequest("GET", "https://www.example.org/")
59+
<HttpRequest [GET], url: 'https://www.example.org/'>
60+
>>> response = client.send_request(request)
61+
<HttpResponse: 200 OK>
62+
63+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
64+
65+
:param request: The network request you want to make. Required.
66+
:type request: ~azure.core.rest.HttpRequest
67+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
68+
:return: The response of your network call. Does not do error handling on your response.
69+
:rtype: ~azure.core.rest.HttpResponse
70+
"""
71+
72+
request_copy = deepcopy(request)
73+
path_format_arguments = {
74+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
75+
}
76+
77+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
78+
return self._client.send_request(request_copy, **kwargs)
79+
80+
def close(self) -> None:
81+
self._client.close()
82+
83+
def __enter__(self) -> "BatchDocumentTranslationClient":
84+
self._client.__enter__()
85+
return self
86+
87+
def __exit__(self, *exc_details) -> None:
88+
self._client.__exit__(*exc_details)

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_generated/_configuration.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,55 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
from typing import TYPE_CHECKING
9+
from typing import Any, TYPE_CHECKING
1010

1111
from azure.core.configuration import Configuration
1212
from azure.core.pipeline import policies
1313

1414
if TYPE_CHECKING:
1515
# pylint: disable=unused-import,ungrouped-imports
16-
from typing import Any
17-
1816
from azure.core.credentials import TokenCredential
1917

2018
VERSION = "unknown"
2119

22-
class BatchDocumentTranslationClientConfiguration(Configuration):
20+
21+
class BatchDocumentTranslationClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
2322
"""Configuration for BatchDocumentTranslationClient.
2423
2524
Note that all parameters used to create this instance are saved as instance
2625
attributes.
2726
28-
:param credential: Credential needed for the client to connect to Azure.
29-
:type credential: ~azure.core.credentials.TokenCredential
30-
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus.api.cognitive.microsoft.com).
27+
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
28+
https://westus.api.cognitive.microsoft.com). Required.
3129
:type endpoint: str
30+
:param credential: Credential needed for the client to connect to Azure. Required.
31+
:type credential: ~azure.core.credentials.TokenCredential
3232
"""
3333

34-
def __init__(
35-
self,
36-
credential, # type: "TokenCredential"
37-
endpoint, # type: str
38-
**kwargs # type: Any
39-
):
40-
# type: (...) -> None
41-
if credential is None:
42-
raise ValueError("Parameter 'credential' must not be None.")
34+
def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
35+
super(BatchDocumentTranslationClientConfiguration, self).__init__(**kwargs)
4336
if endpoint is None:
4437
raise ValueError("Parameter 'endpoint' must not be None.")
45-
super(BatchDocumentTranslationClientConfiguration, self).__init__(**kwargs)
38+
if credential is None:
39+
raise ValueError("Parameter 'credential' must not be None.")
4640

47-
self.credential = credential
4841
self.endpoint = endpoint
49-
self.credential_scopes = kwargs.pop('credential_scopes', ['https://cognitiveservices.azure.com/.default'])
50-
kwargs.setdefault('sdk_moniker', 'ai-translation-document/{}'.format(VERSION))
42+
self.credential = credential
43+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"])
44+
kwargs.setdefault("sdk_moniker", "ai-translation-document/{}".format(VERSION))
5145
self._configure(**kwargs)
5246

53-
def _configure(
54-
self,
55-
**kwargs # type: Any
56-
):
57-
# type: (...) -> None
58-
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
59-
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
60-
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
61-
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
62-
self.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**kwargs)
63-
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
64-
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
65-
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
66-
self.authentication_policy = kwargs.get('authentication_policy')
47+
def _configure(self, **kwargs: Any) -> None:
48+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
49+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
50+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
51+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
52+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
53+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
54+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
55+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
56+
self.authentication_policy = kwargs.get("authentication_policy")
6757
if self.credential and not self.authentication_policy:
68-
self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
58+
self.authentication_policy = policies.BearerTokenCredentialPolicy(
59+
self.credential, *self.credential_scopes, **kwargs
60+
)

0 commit comments

Comments
 (0)