Skip to content

Commit 9f5b369

Browse files
authored
[Monitor Ingestion] Typing and linting fixes (#35193)
This package should now pass next-pyright and next-pylint. Signed-off-by: Paul Van Eck <[email protected]>
1 parent 32c2e5f commit 9f5b369

File tree

4 files changed

+18
-31
lines changed

4 files changed

+18
-31
lines changed

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/_operations/_operations.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# --------------------------------------------------------------------------
99
from io import IOBase
1010
import sys
11-
from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload
11+
from typing import Any, Callable, Dict, IO, List, Optional, Type, TypeVar, Union, overload
1212

1313
from azure.core.exceptions import (
1414
ClientAuthenticationError,
@@ -120,14 +120,11 @@ def _upload( # pylint: disable=inconsistent-return-statements
120120
:type body: list[JSON] or IO[bytes]
121121
:keyword content_encoding: gzip. Default value is None.
122122
:paramtype content_encoding: str
123-
:keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
124-
Default value is None.
125-
:paramtype content_type: str
126123
:return: None
127124
:rtype: None
128125
:raises ~azure.core.exceptions.HttpResponseError:
129126
"""
130-
error_map = {
127+
error_map: MutableMapping[int, Type[HttpResponseError]] = {
131128
401: ClientAuthenticationError,
132129
404: ResourceNotFoundError,
133130
409: ResourceExistsError,

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/_serialization.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@ def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]],
170170
return None
171171

172172

173-
try:
174-
basestring # type: ignore
175-
unicode_str = unicode # type: ignore
176-
except NameError:
177-
basestring = str
178-
unicode_str = str
179-
180173
_LOGGER = logging.getLogger(__name__)
181174

182175
try:
@@ -545,7 +538,7 @@ class Serializer(object):
545538
"multiple": lambda x, y: x % y != 0,
546539
}
547540

548-
def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
541+
def __init__(self, classes: Optional[Mapping[str, type]] = None):
549542
self.serialize_type = {
550543
"iso-8601": Serializer.serialize_iso,
551544
"rfc-1123": Serializer.serialize_rfc,
@@ -561,7 +554,7 @@ def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
561554
"[]": self.serialize_iter,
562555
"{}": self.serialize_dict,
563556
}
564-
self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {}
557+
self.dependencies: Dict[str, type] = dict(classes) if classes else {}
565558
self.key_transformer = full_restapi_key_transformer
566559
self.client_side_validation = True
567560

@@ -649,7 +642,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
649642
else: # That's a basic type
650643
# Integrate namespace if necessary
651644
local_node = _create_xml_node(xml_name, xml_prefix, xml_ns)
652-
local_node.text = unicode_str(new_attr)
645+
local_node.text = str(new_attr)
653646
serialized.append(local_node) # type: ignore
654647
else: # JSON
655648
for k in reversed(keys): # type: ignore
@@ -994,7 +987,7 @@ def serialize_object(self, attr, **kwargs):
994987
return self.serialize_basic(attr, self.basic_types[obj_type], **kwargs)
995988
if obj_type is _long_type:
996989
return self.serialize_long(attr)
997-
if obj_type is unicode_str:
990+
if obj_type is str:
998991
return self.serialize_unicode(attr)
999992
if obj_type is datetime.datetime:
1000993
return self.serialize_iso(attr)
@@ -1370,7 +1363,7 @@ class Deserializer(object):
13701363

13711364
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}]?")
13721365

1373-
def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
1366+
def __init__(self, classes: Optional[Mapping[str, type]] = None):
13741367
self.deserialize_type = {
13751368
"iso-8601": Deserializer.deserialize_iso,
13761369
"rfc-1123": Deserializer.deserialize_rfc,
@@ -1390,7 +1383,7 @@ def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
13901383
"duration": (isodate.Duration, datetime.timedelta),
13911384
"iso-8601": (datetime.datetime),
13921385
}
1393-
self.dependencies: Dict[str, Type[ModelType]] = dict(classes) if classes else {}
1386+
self.dependencies: Dict[str, type] = dict(classes) if classes else {}
13941387
self.key_extractors = [rest_key_extractor, xml_key_extractor]
13951388
# Additional properties only works if the "rest_key_extractor" is used to
13961389
# extract the keys. Making it to work whatever the key extractor is too much
@@ -1443,7 +1436,7 @@ def _deserialize(self, target_obj, data):
14431436

14441437
response, class_name = self._classify_target(target_obj, data)
14451438

1446-
if isinstance(response, basestring):
1439+
if isinstance(response, str):
14471440
return self.deserialize_data(data, response)
14481441
elif isinstance(response, type) and issubclass(response, Enum):
14491442
return self.deserialize_enum(data, response)
@@ -1514,14 +1507,14 @@ def _classify_target(self, target, data):
15141507
if target is None:
15151508
return None, None
15161509

1517-
if isinstance(target, basestring):
1510+
if isinstance(target, str):
15181511
try:
15191512
target = self.dependencies[target]
15201513
except KeyError:
15211514
return target, target
15221515

15231516
try:
1524-
target = target._classify(data, self.dependencies)
1517+
target = target._classify(data, self.dependencies) # type: ignore
15251518
except AttributeError:
15261519
pass # Target is not a Model, no classify
15271520
return target, target.__class__.__name__ # type: ignore
@@ -1577,7 +1570,7 @@ def _unpack_content(raw_data, content_type=None):
15771570
if hasattr(raw_data, "_content_consumed"):
15781571
return RawDeserializer.deserialize_from_http_generics(raw_data.text, raw_data.headers)
15791572

1580-
if isinstance(raw_data, (basestring, bytes)) or hasattr(raw_data, "read"):
1573+
if isinstance(raw_data, (str, bytes)) or hasattr(raw_data, "read"):
15811574
return RawDeserializer.deserialize_from_text(raw_data, content_type) # type: ignore
15821575
return raw_data
15831576

@@ -1699,7 +1692,7 @@ def deserialize_object(self, attr, **kwargs):
16991692
if isinstance(attr, ET.Element):
17001693
# Do no recurse on XML, just return the tree as-is
17011694
return attr
1702-
if isinstance(attr, basestring):
1695+
if isinstance(attr, str):
17031696
return self.deserialize_basic(attr, "str")
17041697
obj_type = type(attr)
17051698
if obj_type in self.basic_types:
@@ -1756,7 +1749,7 @@ def deserialize_basic(self, attr, data_type):
17561749
if data_type == "bool":
17571750
if attr in [True, False, 1, 0]:
17581751
return bool(attr)
1759-
elif isinstance(attr, basestring):
1752+
elif isinstance(attr, str):
17601753
if attr.lower() in ["true", "1"]:
17611754
return True
17621755
elif attr.lower() in ["false", "0"]:

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/aio/_operations/_operations.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# --------------------------------------------------------------------------
99
from io import IOBase
1010
import sys
11-
from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload
11+
from typing import Any, Callable, Dict, IO, List, Optional, Type, TypeVar, Union, overload
1212

1313
from azure.core.exceptions import (
1414
ClientAuthenticationError,
@@ -85,14 +85,11 @@ async def _upload( # pylint: disable=inconsistent-return-statements
8585
:type body: list[JSON] or IO[bytes]
8686
:keyword content_encoding: gzip. Default value is None.
8787
:paramtype content_encoding: str
88-
:keyword content_type: Body Parameter content-type. Known values are: 'application/json'.
89-
Default value is None.
90-
:paramtype content_type: str
9188
:return: None
9289
:rtype: None
9390
:raises ~azure.core.exceptions.HttpResponseError:
9491
"""
95-
error_map = {
92+
error_map: MutableMapping[int, Type[HttpResponseError]] = {
9693
401: ClientAuthenticationError,
9794
404: ResourceNotFoundError,
9895
409: ResourceExistsError,

sdk/monitor/azure-monitor-ingestion/azure/monitor/ingestion/aio/_operations/_patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ async def upload(
4343
4444
:param rule_id: The immutable ID of the Data Collection Rule resource.
4545
:type rule_id: str
46-
:param stream: The streamDeclaration name as defined in the Data Collection Rule.
47-
:type stream: str
46+
:param stream_name: The streamDeclaration name as defined in the Data Collection Rule.
47+
:type stream_name: str
4848
:param logs: An array of objects matching the schema defined by the provided stream.
4949
:type logs: list[JSON] or IO
5050
:keyword on_error: The callback function that is called when a chunk of logs fails to upload.

0 commit comments

Comments
 (0)