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

[AutoPR track2_azure-mgmt-kusto] [Hub Generated] Publish private branch 'azure-kusto/devCM' #2493

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions sdk/kusto/azure-mgmt-kusto/_meta.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"commit": "89a9bf17524904e7670f0fd2d62ac882ca00d85c",
"commit": "c4ff1eb1e70423dccff8b3f97aa040fae48acb98",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"autorest": "3.9.2",
"use": [
"@autorest/python@6.2.7",
"@autorest/python@6.2.16",
"@autorest/modelerfour@4.24.3"
],
"autorest_command": "autorest specification/azure-kusto/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/home/vsts/work/1/azure-sdk-for-python/sdk --use=@autorest/python@6.2.7 --use=@autorest/modelerfour@4.24.3 --version=3.9.2 --version-tolerant=False",
"autorest_command": "autorest specification/azure-kusto/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/mnt/vss/_work/1/s/azure-sdk-for-python/sdk --use=@autorest/python@6.2.16 --use=@autorest/modelerfour@4.24.3 --version=3.9.2 --version-tolerant=False",
"readme": "specification/azure-kusto/resource-manager/readme.md"
}
4 changes: 2 additions & 2 deletions sdk/kusto/azure-mgmt-kusto/azure/mgmt/kusto/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class KustoManagementClientConfiguration(Configuration): # pylint: disable=too-
:param subscription_id: Gets subscription credentials which uniquely identify Microsoft Azure
subscription. The subscription ID forms part of the URI for every service call. Required.
:type subscription_id: str
:keyword api_version: Api Version. Default value is "2022-11-11". Note that overriding this
:keyword api_version: Api Version. Default value is "2022-12-29". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None:
super(KustoManagementClientConfiguration, self).__init__(**kwargs)
api_version: Literal["2022-11-11"] = kwargs.pop("api_version", "2022-11-11")
api_version: Literal["2022-12-29"] = kwargs.pop("api_version", "2022-12-29")

if credential is None:
raise ValueError("Parameter 'credential' must not be None.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class KustoManagementClient: # pylint: disable=client-accepts-api-version-keywo
:type subscription_id: str
:param base_url: Service URL. Default value is "https://management.azure.com".
:type base_url: str
:keyword api_version: Api Version. Default value is "2022-11-11". Note that overriding this
:keyword api_version: Api Version. Default value is "2022-12-29". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Expand Down
87 changes: 58 additions & 29 deletions sdk/kusto/azure-mgmt-kusto/azure/mgmt/kusto/_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@
import re
import sys
import codecs
from typing import Optional, Union, AnyStr, IO, Mapping
from typing import (
Dict,
Any,
cast,
Optional,
Union,
AnyStr,
IO,
Mapping,
Callable,
TypeVar,
MutableMapping,
Type,
List,
Mapping,
)

try:
from urllib import quote # type: ignore
Expand All @@ -48,12 +63,14 @@

import isodate # type: ignore

from typing import Dict, Any, cast

from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback
from azure.core.serialization import NULL as AzureCoreNull

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

ModelType = TypeVar("ModelType", bound="Model")
JSON = MutableMapping[str, Any]


class RawDeserializer:

Expand Down Expand Up @@ -277,8 +294,8 @@ class Model(object):
_attribute_map: Dict[str, Dict[str, Any]] = {}
_validation: Dict[str, Dict[str, Any]] = {}

def __init__(self, **kwargs):
self.additional_properties = {}
def __init__(self, **kwargs: Any) -> None:
self.additional_properties: Dict[str, Any] = {}
for k in kwargs:
if k not in self._attribute_map:
_LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__)
Expand All @@ -287,25 +304,25 @@ def __init__(self, **kwargs):
else:
setattr(self, k, kwargs[k])

def __eq__(self, other):
def __eq__(self, other: Any) -> bool:
"""Compare objects by comparing all attributes."""
if isinstance(other, self.__class__):
return self.__dict__ == other.__dict__
return False

def __ne__(self, other):
def __ne__(self, other: Any) -> bool:
"""Compare objects by comparing all attributes."""
return not self.__eq__(other)

def __str__(self):
def __str__(self) -> str:
return str(self.__dict__)

@classmethod
def enable_additional_properties_sending(cls):
def enable_additional_properties_sending(cls) -> None:
cls._attribute_map["additional_properties"] = {"key": "", "type": "{object}"}

@classmethod
def is_xml_model(cls):
def is_xml_model(cls) -> bool:
try:
cls._xml_map # type: ignore
except AttributeError:
Expand All @@ -322,7 +339,7 @@ def _create_xml_node(cls):

return _create_xml_node(xml_map.get("name", cls.__name__), xml_map.get("prefix", None), xml_map.get("ns", None))

def serialize(self, keep_readonly=False, **kwargs):
def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON:
"""Return the JSON that would be sent to azure from this model.

This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`.
Expand All @@ -336,8 +353,13 @@ def serialize(self, keep_readonly=False, **kwargs):
serializer = Serializer(self._infer_class_models())
return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs)

def as_dict(self, keep_readonly=True, key_transformer=attribute_transformer, **kwargs):
"""Return a dict that can be JSONify using json.dump.
def as_dict(
self,
keep_readonly: bool = True,
key_transformer: Callable[[str, Dict[str, Any], Any], Any] = attribute_transformer,
**kwargs: Any
) -> JSON:
"""Return a dict that can be serialized using json.dump.

Advanced usage might optionally use a callback as parameter:

Expand Down Expand Up @@ -384,7 +406,7 @@ def _infer_class_models(cls):
return client_models

@classmethod
def deserialize(cls, data, content_type=None):
def deserialize(cls: Type[ModelType], data: Any, content_type: Optional[str] = None) -> ModelType:
"""Parse a str using the RestAPI syntax and return a model.

:param str data: A str using RestAPI structure. JSON by default.
Expand All @@ -396,7 +418,12 @@ def deserialize(cls, data, content_type=None):
return deserializer(cls.__name__, data, content_type=content_type)

@classmethod
def from_dict(cls, data, key_extractors=None, content_type=None):
def from_dict(
cls: Type[ModelType],
data: Any,
key_extractors: Optional[Callable[[str, Dict[str, Any], Any], Any]] = None,
content_type: Optional[str] = None,
) -> ModelType:
"""Parse a dict using given key extractor return a model.

By default consider key
Expand All @@ -409,8 +436,8 @@ def from_dict(cls, data, key_extractors=None, content_type=None):
:raises: DeserializationError if something went wrong
"""
deserializer = Deserializer(cls._infer_class_models())
deserializer.key_extractors = (
[
deserializer.key_extractors = ( # type: ignore
[ # type: ignore
attribute_key_case_insensitive_extractor,
rest_key_case_insensitive_extractor,
last_rest_key_case_insensitive_extractor,
Expand Down Expand Up @@ -518,7 +545,7 @@ class Serializer(object):
"multiple": lambda x, y: x % y != 0,
}

def __init__(self, classes=None):
def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
self.serialize_type = {
"iso-8601": Serializer.serialize_iso,
"rfc-1123": Serializer.serialize_rfc,
Expand All @@ -534,7 +561,7 @@ def __init__(self, classes=None):
"[]": self.serialize_iter,
"{}": self.serialize_dict,
}
self.dependencies = dict(classes) if classes else {}
self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {}
self.key_transformer = full_restapi_key_transformer
self.client_side_validation = True

Expand Down Expand Up @@ -626,8 +653,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
serialized.append(local_node) # type: ignore
else: # JSON
for k in reversed(keys): # type: ignore
unflattened = {k: new_attr}
new_attr = unflattened
new_attr = {k: new_attr}

_new_attr = new_attr
_serialized = serialized
Expand Down Expand Up @@ -656,8 +682,8 @@ def body(self, data, data_type, **kwargs):
"""

# Just in case this is a dict
internal_data_type = data_type.strip("[]{}")
internal_data_type = self.dependencies.get(internal_data_type, None)
internal_data_type_str = data_type.strip("[]{}")
internal_data_type = self.dependencies.get(internal_data_type_str, None)
try:
is_xml_model_serialization = kwargs["is_xml"]
except KeyError:
Expand Down Expand Up @@ -777,6 +803,8 @@ def serialize_data(self, data, data_type, **kwargs):
raise ValueError("No value for given attribute")

try:
if data is AzureCoreNull:
return None
if data_type in self.basic_types.values():
return self.serialize_basic(data, data_type, **kwargs)

Expand Down Expand Up @@ -1161,7 +1189,8 @@ def rest_key_extractor(attr, attr_desc, data):
working_data = data

while "." in key:
dict_keys = _FLATTEN.split(key)
# Need the cast, as for some reasons "split" is typed as list[str | Any]
dict_keys = cast(List[str], _FLATTEN.split(key))
if len(dict_keys) == 1:
key = _decode_attribute_map_key(dict_keys[0])
break
Expand Down Expand Up @@ -1332,7 +1361,7 @@ class Deserializer(object):

valid_date = re.compile(r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}" r"\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?")

def __init__(self, classes=None):
def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
self.deserialize_type = {
"iso-8601": Deserializer.deserialize_iso,
"rfc-1123": Deserializer.deserialize_rfc,
Expand All @@ -1352,7 +1381,7 @@ def __init__(self, classes=None):
"duration": (isodate.Duration, datetime.timedelta),
"iso-8601": (datetime.datetime),
}
self.dependencies = dict(classes) if classes else {}
self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {}
self.key_extractors = [rest_key_extractor, xml_key_extractor]
# Additional properties only works if the "rest_key_extractor" is used to
# extract the keys. Making it to work whatever the key extractor is too much
Expand Down Expand Up @@ -1471,7 +1500,7 @@ def _classify_target(self, target, data):
Once classification has been determined, initialize object.

:param str target: The target object type to deserialize to.
:param str/dict data: The response data to deseralize.
:param str/dict data: The response data to deserialize.
"""
if target is None:
return None, None
Expand All @@ -1486,7 +1515,7 @@ def _classify_target(self, target, data):
target = target._classify(data, self.dependencies)
except AttributeError:
pass # Target is not a Model, no classify
return target, target.__class__.__name__
return target, target.__class__.__name__ # type: ignore

def failsafe_deserialize(self, target_obj, data, content_type=None):
"""Ignores any errors encountered in deserialization,
Expand All @@ -1496,7 +1525,7 @@ def failsafe_deserialize(self, target_obj, data, content_type=None):
a deserialization error.

:param str target_obj: The target object type to deserialize to.
:param str/dict data: The response data to deseralize.
:param str/dict data: The response data to deserialize.
:param str content_type: Swagger "produces" if available.
"""
try:
Expand Down
5 changes: 4 additions & 1 deletion sdk/kusto/azure-mgmt-kusto/azure/mgmt/kusto/_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import List, cast

from azure.core.pipeline.transport import HttpRequest


Expand All @@ -22,6 +24,7 @@ def _format_url_section(template, **kwargs):
try:
return template.format(**kwargs)
except KeyError as key:
formatted_components = template.split("/")
# Need the cast, as for some reasons "split" is typed as list[str | Any]
formatted_components = cast(List[str], template.split("/"))
components = [c for c in formatted_components if "{}".format(key.args[0]) not in c]
template = "/".join(components)
2 changes: 1 addition & 1 deletion sdk/kusto/azure-mgmt-kusto/azure/mgmt/kusto/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

VERSION = "3.1.0b1"
VERSION = "2.0.0b1"
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class KustoManagementClientConfiguration(Configuration): # pylint: disable=too-
:param subscription_id: Gets subscription credentials which uniquely identify Microsoft Azure
subscription. The subscription ID forms part of the URI for every service call. Required.
:type subscription_id: str
:keyword api_version: Api Version. Default value is "2022-11-11". Note that overriding this
:keyword api_version: Api Version. Default value is "2022-12-29". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None:
super(KustoManagementClientConfiguration, self).__init__(**kwargs)
api_version: Literal["2022-11-11"] = kwargs.pop("api_version", "2022-11-11")
api_version: Literal["2022-12-29"] = kwargs.pop("api_version", "2022-12-29")

if credential is None:
raise ValueError("Parameter 'credential' must not be None.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class KustoManagementClient: # pylint: disable=client-accepts-api-version-keywo
:type subscription_id: str
:param base_url: Service URL. Default value is "https://management.azure.com".
:type base_url: str
:keyword api_version: Api Version. Default value is "2022-11-11". Note that overriding this
:keyword api_version: Api Version. Default value is "2022-12-29". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async def check_name_availability(
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

api_version: Literal["2022-11-11"] = kwargs.pop(
api_version: Literal["2022-12-29"] = kwargs.pop(
"api_version", _params.pop("api-version", self._config.api_version)
)
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
Expand Down Expand Up @@ -233,7 +233,7 @@ def list_by_cluster(
_headers = kwargs.pop("headers", {}) or {}
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

api_version: Literal["2022-11-11"] = kwargs.pop(
api_version: Literal["2022-12-29"] = kwargs.pop(
"api_version", _params.pop("api-version", self._config.api_version)
)
cls: ClsType[_models.AttachedDatabaseConfigurationListResult] = kwargs.pop("cls", None)
Expand Down Expand Up @@ -336,7 +336,7 @@ async def get(
_headers = kwargs.pop("headers", {}) or {}
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

api_version: Literal["2022-11-11"] = kwargs.pop(
api_version: Literal["2022-12-29"] = kwargs.pop(
"api_version", _params.pop("api-version", self._config.api_version)
)
cls: ClsType[_models.AttachedDatabaseConfiguration] = kwargs.pop("cls", None)
Expand Down Expand Up @@ -394,7 +394,7 @@ async def _create_or_update_initial(
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

api_version: Literal["2022-11-11"] = kwargs.pop(
api_version: Literal["2022-12-29"] = kwargs.pop(
"api_version", _params.pop("api-version", self._config.api_version)
)
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
Expand Down Expand Up @@ -576,7 +576,7 @@ async def begin_create_or_update(
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

api_version: Literal["2022-11-11"] = kwargs.pop(
api_version: Literal["2022-12-29"] = kwargs.pop(
"api_version", _params.pop("api-version", self._config.api_version)
)
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
Expand Down Expand Up @@ -638,7 +638,7 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements
_headers = kwargs.pop("headers", {}) or {}
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

api_version: Literal["2022-11-11"] = kwargs.pop(
api_version: Literal["2022-12-29"] = kwargs.pop(
"api_version", _params.pop("api-version", self._config.api_version)
)
cls: ClsType[None] = kwargs.pop("cls", None)
Expand Down Expand Up @@ -702,7 +702,7 @@ async def begin_delete(
_headers = kwargs.pop("headers", {}) or {}
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

api_version: Literal["2022-11-11"] = kwargs.pop(
api_version: Literal["2022-12-29"] = kwargs.pop(
"api_version", _params.pop("api-version", self._config.api_version)
)
cls: ClsType[None] = kwargs.pop("cls", None)
Expand Down
Loading