Skip to content

Commit b25a030

Browse files
[QA] regen for next-pyright/pylint (Azure#32053)
* regen for next-pyright/pylint * regen after autorest bug fix * ignore pylint in gen code for now until actual fix in generator
1 parent 3a90a6f commit b25a030

File tree

15 files changed

+669
-208
lines changed

15 files changed

+669
-208
lines changed

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class QuestionAnsweringClient(
4141
def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any) -> None:
4242
_endpoint = "{Endpoint}/language"
4343
self._config = QuestionAnsweringClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
44-
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
44+
self._client: PipelineClient = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
4545

4646
client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
4747
self._serialize = Serializer(client_models)
@@ -81,5 +81,5 @@ def __enter__(self) -> "QuestionAnsweringClient":
8181
self._client.__enter__()
8282
return self
8383

84-
def __exit__(self, *exc_details) -> None:
84+
def __exit__(self, *exc_details: Any) -> None:
8585
self._client.__exit__(*exc_details)

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_configuration.py

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

9-
import sys
109
from typing import Any
1110

1211
from azure.core.configuration import Configuration
@@ -15,13 +14,8 @@
1514

1615
from ._version import VERSION
1716

18-
if sys.version_info >= (3, 8):
19-
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
20-
else:
21-
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
2217

23-
24-
class QuestionAnsweringClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
18+
class QuestionAnsweringClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes,name-too-long
2519
"""Configuration for QuestionAnsweringClient.
2620
2721
Note that all parameters used to create this instance are saved as instance
@@ -39,7 +33,7 @@ class QuestionAnsweringClientConfiguration(Configuration): # pylint: disable=to
3933

4034
def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any) -> None:
4135
super(QuestionAnsweringClientConfiguration, self).__init__(**kwargs)
42-
api_version: Literal["2021-10-01"] = kwargs.pop("api_version", "2021-10-01")
36+
api_version: str = kwargs.pop("api_version", "2021-10-01")
4337

4438
if endpoint is None:
4539
raise ValueError("Parameter 'endpoint' must not be None.")

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_operations/_operations.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# pylint: disable=too-many-lines
1+
# pylint: disable=too-many-lines,too-many-statements
22
# coding=utf-8
33
# --------------------------------------------------------------------------
44
# Copyright (c) Microsoft Corporation. All rights reserved.
55
# Licensed under the MIT License. See License.txt in the project root for license information.
66
# Code generated by Microsoft (R) AutoRest Code Generator.
77
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
88
# --------------------------------------------------------------------------
9-
import sys
9+
from io import IOBase
1010
from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload
1111

1212
from azure.core.exceptions import (
@@ -18,19 +18,14 @@
1818
map_error,
1919
)
2020
from azure.core.pipeline import PipelineResponse
21-
from azure.core.pipeline.transport import HttpResponse
22-
from azure.core.rest import HttpRequest
21+
from azure.core.rest import HttpRequest, HttpResponse
2322
from azure.core.tracing.decorator import distributed_trace
2423
from azure.core.utils import case_insensitive_dict
2524

2625
from .. import models as _models
2726
from .._serialization import Serializer
2827
from .._vendor import QuestionAnsweringClientMixinABC
2928

30-
if sys.version_info >= (3, 8):
31-
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
32-
else:
33-
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
3429
T = TypeVar("T")
3530
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
3631

@@ -45,7 +40,7 @@ def build_question_answering_get_answers_request( # pylint: disable=name-too-lo
4540
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
4641

4742
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
48-
api_version: Literal["2021-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2021-10-01"))
43+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-10-01"))
4944
accept = _headers.pop("Accept", "application/json")
5045

5146
# Construct URL
@@ -64,12 +59,14 @@ def build_question_answering_get_answers_request( # pylint: disable=name-too-lo
6459
return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)
6560

6661

67-
def build_question_answering_get_answers_from_text_request(**kwargs: Any) -> HttpRequest: # pylint: disable=name-too-long
62+
def build_question_answering_get_answers_from_text_request( # pylint: disable=name-too-long
63+
**kwargs: Any,
64+
) -> HttpRequest:
6865
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
6966
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
7067

7168
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
72-
api_version: Literal["2021-10-01"] = kwargs.pop("api_version", _params.pop("api-version", "2021-10-01"))
69+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2021-10-01"))
7370
accept = _headers.pop("Accept", "application/json")
7471

7572
# Construct URL
@@ -95,7 +92,7 @@ def get_answers(
9592
project_name: str,
9693
deployment_name: str,
9794
content_type: str = "application/json",
98-
**kwargs: Any
95+
**kwargs: Any,
9996
) -> _models.AnswersResult:
10097
"""Answers the specified question using your knowledge base.
10198
@@ -123,7 +120,7 @@ def get_answers(
123120
project_name: str,
124121
deployment_name: str,
125122
content_type: str = "application/json",
126-
**kwargs: Any
123+
**kwargs: Any,
127124
) -> _models.AnswersResult:
128125
"""Answers the specified question using your knowledge base.
129126
@@ -151,7 +148,8 @@ def get_answers(
151148
152149
Answers the specified question using your knowledge base.
153150
154-
:param options: Post body of the request. Is either a model type or a IO type. Required.
151+
:param options: Post body of the request. Is either a AnswersOptions type or a IO type.
152+
Required.
155153
:type options: ~azure.ai.language.questionanswering.models.AnswersOptions or IO
156154
:keyword project_name: The name of the project to use. Required.
157155
:paramtype project_name: str
@@ -181,7 +179,7 @@ def get_answers(
181179
content_type = content_type or "application/json"
182180
_json = None
183181
_content = None
184-
if isinstance(options, (IO, bytes)):
182+
if isinstance(options, (IOBase, bytes)):
185183
_content = options
186184
else:
187185
_json = self._serialize.body(options, "AnswersOptions")
@@ -201,13 +199,16 @@ def get_answers(
201199
}
202200
request.url = self._client.format_url(request.url, **path_format_arguments)
203201

202+
_stream = False
204203
pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
205-
request, stream=False, **kwargs
204+
request, stream=_stream, **kwargs
206205
)
207206

208207
response = pipeline_response.http_response
209208

210209
if response.status_code not in [200]:
210+
if _stream:
211+
response.read() # Load the body in memory and close the socket
211212
map_error(status_code=response.status_code, response=response, error_map=error_map)
212213
error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response)
213214
raise HttpResponseError(response=response, model=error)
@@ -263,7 +264,8 @@ def get_answers_from_text(
263264
264265
Answers the specified question using the provided text in the body.
265266
266-
:param options: Post body of the request. Is either a model type or a IO type. Required.
267+
:param options: Post body of the request. Is either a AnswersFromTextOptions type or a IO type.
268+
Required.
267269
:type options: ~azure.ai.language.questionanswering.models.AnswersFromTextOptions or IO
268270
:keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
269271
Default value is None.
@@ -289,7 +291,7 @@ def get_answers_from_text(
289291
content_type = content_type or "application/json"
290292
_json = None
291293
_content = None
292-
if isinstance(options, (IO, bytes)):
294+
if isinstance(options, (IOBase, bytes)):
293295
_content = options
294296
else:
295297
_json = self._serialize.body(options, "AnswersFromTextOptions")
@@ -307,13 +309,16 @@ def get_answers_from_text(
307309
}
308310
request.url = self._client.format_url(request.url, **path_format_arguments)
309311

312+
_stream = False
310313
pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
311-
request, stream=False, **kwargs
314+
request, stream=_stream, **kwargs
312315
)
313316

314317
response = pipeline_response.http_response
315318

316319
if response.status_code not in [200]:
320+
if _stream:
321+
response.read() # Load the body in memory and close the socket
317322
map_error(status_code=response.status_code, response=response, error_map=error_map)
318323
error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response)
319324
raise HttpResponseError(response=response, model=error)

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/_serialization.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import isodate # type: ignore
6565

6666
from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback
67+
from azure.core.serialization import NULL as AzureCoreNull
6768

6869
_BOM = codecs.BOM_UTF8.decode(encoding="utf-8")
6970

@@ -628,7 +629,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
628629
if xml_desc.get("attr", False):
629630
if xml_ns:
630631
ET.register_namespace(xml_prefix, xml_ns)
631-
xml_name = "{}{}".format(xml_ns, xml_name)
632+
xml_name = "{{{}}}{}".format(xml_ns, xml_name)
632633
serialized.set(xml_name, new_attr) # type: ignore
633634
continue
634635
if xml_desc.get("text", False):
@@ -661,8 +662,9 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
661662
_serialized.update(_new_attr) # type: ignore
662663
_new_attr = _new_attr[k] # type: ignore
663664
_serialized = _serialized[k]
664-
except ValueError:
665-
continue
665+
except ValueError as err:
666+
if isinstance(err, SerializationError):
667+
raise
666668

667669
except (AttributeError, KeyError, TypeError) as err:
668670
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj))
@@ -728,6 +730,8 @@ def url(self, name, data, data_type, **kwargs):
728730

729731
if kwargs.get("skip_quote") is True:
730732
output = str(output)
733+
# https://github.com/Azure/autorest.python/issues/2063
734+
output = output.replace("{", quote("{")).replace("}", quote("}"))
731735
else:
732736
output = quote(str(output), safe="")
733737
except SerializationError:
@@ -740,6 +744,8 @@ def query(self, name, data, data_type, **kwargs):
740744
741745
:param data: The data to be serialized.
742746
:param str data_type: The type to be serialized from.
747+
:keyword bool skip_quote: Whether to skip quote the serialized result.
748+
Defaults to False.
743749
:rtype: str
744750
:raises: TypeError if serialization fails.
745751
:raises: ValueError if data is None
@@ -748,10 +754,8 @@ def query(self, name, data, data_type, **kwargs):
748754
# Treat the list aside, since we don't want to encode the div separator
749755
if data_type.startswith("["):
750756
internal_data_type = data_type[1:-1]
751-
data = [self.serialize_data(d, internal_data_type, **kwargs) if d is not None else "" for d in data]
752-
if not kwargs.get("skip_quote", False):
753-
data = [quote(str(d), safe="") for d in data]
754-
return str(self.serialize_iter(data, internal_data_type, **kwargs))
757+
do_quote = not kwargs.get("skip_quote", False)
758+
return str(self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs))
755759

756760
# Not a list, regular serialization
757761
output = self.serialize_data(data, data_type, **kwargs)
@@ -802,6 +806,8 @@ def serialize_data(self, data, data_type, **kwargs):
802806
raise ValueError("No value for given attribute")
803807

804808
try:
809+
if data is AzureCoreNull:
810+
return None
805811
if data_type in self.basic_types.values():
806812
return self.serialize_basic(data, data_type, **kwargs)
807813

@@ -888,6 +894,8 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs):
888894
not be None or empty.
889895
:param str div: If set, this str will be used to combine the elements
890896
in the iterable into a combined string. Default is 'None'.
897+
:keyword bool do_quote: Whether to quote the serialized result of each iterable element.
898+
Defaults to False.
891899
:rtype: list, str
892900
"""
893901
if isinstance(data, str):
@@ -900,9 +908,14 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs):
900908
for d in data:
901909
try:
902910
serialized.append(self.serialize_data(d, iter_type, **kwargs))
903-
except ValueError:
911+
except ValueError as err:
912+
if isinstance(err, SerializationError):
913+
raise
904914
serialized.append(None)
905915

916+
if kwargs.get("do_quote", False):
917+
serialized = ["" if s is None else quote(str(s), safe="") for s in serialized]
918+
906919
if div:
907920
serialized = ["" if s is None else str(s) for s in serialized]
908921
serialized = div.join(serialized)
@@ -947,7 +960,9 @@ def serialize_dict(self, attr, dict_type, **kwargs):
947960
for key, value in attr.items():
948961
try:
949962
serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs)
950-
except ValueError:
963+
except ValueError as err:
964+
if isinstance(err, SerializationError):
965+
raise
951966
serialized[self.serialize_unicode(key)] = None
952967

953968
if "xml" in serialization_ctxt:
@@ -1268,7 +1283,7 @@ def _extract_name_from_internal_type(internal_type):
12681283
xml_name = internal_type_xml_map.get("name", internal_type.__name__)
12691284
xml_ns = internal_type_xml_map.get("ns", None)
12701285
if xml_ns:
1271-
xml_name = "{}{}".format(xml_ns, xml_name)
1286+
xml_name = "{{{}}}{}".format(xml_ns, xml_name)
12721287
return xml_name
12731288

12741289

@@ -1292,7 +1307,7 @@ def xml_key_extractor(attr, attr_desc, data):
12921307
# Integrate namespace if necessary
12931308
xml_ns = xml_desc.get("ns", internal_type_xml_map.get("ns", None))
12941309
if xml_ns:
1295-
xml_name = "{}{}".format(xml_ns, xml_name)
1310+
xml_name = "{{{}}}{}".format(xml_ns, xml_name)
12961311

12971312
# If it's an attribute, that's simple
12981313
if xml_desc.get("attr", False):
@@ -1897,7 +1912,7 @@ def deserialize_date(attr):
18971912
if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore
18981913
raise DeserializationError("Date must have only digits and -. Received: %s" % attr)
18991914
# This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception.
1900-
return isodate.parse_date(attr, defaultmonth=None, defaultday=None)
1915+
return isodate.parse_date(attr, defaultmonth=0, defaultday=0)
19011916

19021917
@staticmethod
19031918
def deserialize_time(attr):

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class QuestionAnsweringClient(
4141
def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any) -> None:
4242
_endpoint = "{Endpoint}/language"
4343
self._config = QuestionAnsweringClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
44-
self._client = AsyncPipelineClient(base_url=_endpoint, config=self._config, **kwargs)
44+
self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=_endpoint, config=self._config, **kwargs)
4545

4646
client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
4747
self._serialize = Serializer(client_models)
@@ -81,5 +81,5 @@ async def __aenter__(self) -> "QuestionAnsweringClient":
8181
await self._client.__aenter__()
8282
return self
8383

84-
async def __aexit__(self, *exc_details) -> None:
84+
async def __aexit__(self, *exc_details: Any) -> None:
8585
await self._client.__aexit__(*exc_details)

sdk/cognitivelanguage/azure-ai-language-questionanswering/azure/ai/language/questionanswering/aio/_configuration.py

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

9-
import sys
109
from typing import Any
1110

1211
from azure.core.configuration import Configuration
@@ -15,13 +14,8 @@
1514

1615
from .._version import VERSION
1716

18-
if sys.version_info >= (3, 8):
19-
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
20-
else:
21-
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
2217

23-
24-
class QuestionAnsweringClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
18+
class QuestionAnsweringClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes,name-too-long
2519
"""Configuration for QuestionAnsweringClient.
2620
2721
Note that all parameters used to create this instance are saved as instance
@@ -39,7 +33,7 @@ class QuestionAnsweringClientConfiguration(Configuration): # pylint: disable=to
3933

4034
def __init__(self, endpoint: str, credential: AzureKeyCredential, **kwargs: Any) -> None:
4135
super(QuestionAnsweringClientConfiguration, self).__init__(**kwargs)
42-
api_version: Literal["2021-10-01"] = kwargs.pop("api_version", "2021-10-01")
36+
api_version: str = kwargs.pop("api_version", "2021-10-01")
4337

4438
if endpoint is None:
4539
raise ValueError("Parameter 'endpoint' must not be None.")

0 commit comments

Comments
 (0)