Skip to content

Commit bf50574

Browse files
authored
Remove a bit of Python 2.7 code (#38735)
* Remove a bit of Python 2.7 code * Fix typo * Remove _str consistently * More replacements * fix mock * fix * reset stuff * Reset changes in legacy servicemanagement * fix _str * fix * pylint --------- Co-authored-by: Mads Jensen <[email protected]>
1 parent 980fe42 commit bf50574

File tree

21 files changed

+76
-224
lines changed

21 files changed

+76
-224
lines changed

sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/avro/schema.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,10 @@
2525
- Null.
2626
"""
2727

28-
import abc
28+
from abc import ABCMeta, abstractmethod
2929
import json
3030
import logging
3131
import re
32-
import sys
33-
from six import with_metaclass
34-
35-
PY2 = sys.version_info[0] == 2
36-
37-
if PY2:
38-
_str = unicode # pylint: disable=undefined-variable
39-
else:
40-
_str = str
4132

4233
logger = logging.getLogger(__name__)
4334

@@ -140,7 +131,7 @@ class SchemaParseException(AvroException):
140131
"""Error while parsing a JSON schema descriptor."""
141132

142133

143-
class Schema(with_metaclass(abc.ABCMeta, object)):
134+
class Schema(metaclass=ABCMeta):
144135
"""Abstract base class for all Schema classes."""
145136

146137
def __init__(self, data_type, other_props=None):
@@ -198,7 +189,7 @@ def __str__(self):
198189
"""Returns: the JSON representation of this schema."""
199190
return json.dumps(self.to_json(names=None))
200191

201-
@abc.abstractmethod
192+
@abstractmethod
202193
def to_json(self, names):
203194
"""Converts the schema object into its AVRO specification representation.
204195
@@ -286,7 +277,7 @@ def fullname(self):
286277
# ------------------------------------------------------------------------------
287278

288279

289-
class Names(object):
280+
class Names:
290281
"""Tracks Avro named schemas and default namespace during parsing."""
291282

292283
def __init__(self, default_namespace=None, names=None):
@@ -447,7 +438,7 @@ def name_ref(self, names):
447438
return self.name
448439
return self.fullname
449440

450-
@abc.abstractmethod
441+
@abstractmethod
451442
def to_json(self, names):
452443
"""Converts the schema object into its AVRO specification representation.
453444
@@ -489,7 +480,7 @@ def __init__(
489480
doc:
490481
other_props:
491482
"""
492-
if (not isinstance(name, _str)) or (not name):
483+
if (not isinstance(name, str)) or (not name):
493484
raise SchemaParseException('Invalid record field name: %r.' % name)
494485
if (order is not None) and (order not in VALID_FIELD_SORT_ORDERS):
495486
raise SchemaParseException('Invalid record field order: %r.' % order)
@@ -564,8 +555,8 @@ def to_json(self, names=None):
564555
return to_dump
565556

566557
def __eq__(self, that):
567-
to_cmp = json.loads(_str(self))
568-
return to_cmp == json.loads(_str(that))
558+
to_cmp = json.loads(str(self))
559+
return to_cmp == json.loads(str(that))
569560

570561

571562
# ------------------------------------------------------------------------------
@@ -679,7 +670,7 @@ def __init__(
679670
symbols = tuple(symbols)
680671
symbol_set = frozenset(symbols)
681672
if (len(symbol_set) != len(symbols)
682-
or not all(map(lambda symbol: isinstance(symbol, _str), symbols))):
673+
or not all(map(lambda symbol: isinstance(symbol, str), symbols))):
683674
raise AvroException(
684675
'Invalid symbols for enum schema: %r.' % (symbols,))
685676

@@ -747,8 +738,8 @@ def to_json(self, names=None):
747738
return to_dump
748739

749740
def __eq__(self, that):
750-
to_cmp = json.loads(_str(self))
751-
return to_cmp == json.loads(_str(that))
741+
to_cmp = json.loads(str(self))
742+
return to_cmp == json.loads(str(that))
752743

753744

754745
# ------------------------------------------------------------------------------
@@ -784,8 +775,8 @@ def to_json(self, names=None):
784775
return to_dump
785776

786777
def __eq__(self, that):
787-
to_cmp = json.loads(_str(self))
788-
return to_cmp == json.loads(_str(that))
778+
to_cmp = json.loads(str(self))
779+
return to_cmp == json.loads(str(that))
789780

790781

791782
# ------------------------------------------------------------------------------
@@ -841,8 +832,8 @@ def to_json(self, names=None):
841832
return to_dump
842833

843834
def __eq__(self, that):
844-
to_cmp = json.loads(_str(self))
845-
return to_cmp == json.loads(_str(that))
835+
to_cmp = json.loads(str(self))
836+
return to_cmp == json.loads(str(that))
846837

847838

848839
# ------------------------------------------------------------------------------
@@ -1031,8 +1022,8 @@ def to_json(self, names=None):
10311022
return to_dump
10321023

10331024
def __eq__(self, that):
1034-
to_cmp = json.loads(_str(self))
1035-
return to_cmp == json.loads(_str(that))
1025+
to_cmp = json.loads(str(self))
1026+
return to_cmp == json.loads(str(that))
10361027

10371028

10381029
# ------------------------------------------------------------------------------
@@ -1164,7 +1155,7 @@ def MakeFields(names):
11641155

11651156
# Parsers for the JSON data types:
11661157
_JSONDataParserTypeMap = {
1167-
_str: _schema_from_json_string,
1158+
str: _schema_from_json_string,
11681159
list: _schema_from_json_array,
11691160
dict: _schema_from_json_object,
11701161
}

sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/parser.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@
66

77
import sys
88

9-
if sys.version_info < (3,):
10-
def _str(value):
11-
if isinstance(value, unicode): # pylint: disable=undefined-variable
12-
return value.encode('utf-8')
13-
14-
return str(value)
15-
else:
16-
_str = str
17-
189

1910
def _to_utc_datetime(value):
2011
return value.strftime('%Y-%m-%dT%H:%M:%SZ')

sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/policies.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,12 @@
1515
import types
1616
from typing import Any, TYPE_CHECKING
1717
from wsgiref.handlers import format_date_time
18-
try:
19-
from urllib.parse import (
20-
urlparse,
21-
parse_qsl,
22-
urlunparse,
23-
urlencode,
24-
)
25-
except ImportError:
26-
from urllib import urlencode # type: ignore
27-
from urlparse import ( # type: ignore
28-
urlparse,
29-
parse_qsl,
30-
urlunparse,
31-
)
18+
from urllib.parse import (
19+
urlparse,
20+
parse_qsl,
21+
urlunparse,
22+
urlencode,
23+
)
3224

3325
from azure.core.pipeline.policies import (
3426
HeadersPolicy,
@@ -41,10 +33,6 @@
4133

4234
from .models import LocationMode
4335

44-
try:
45-
_unicode_type = unicode # type: ignore
46-
except NameError:
47-
_unicode_type = str
4836

4937
if TYPE_CHECKING:
5038
from azure.core.pipeline import PipelineRequest, PipelineResponse
@@ -54,8 +42,6 @@
5442

5543

5644
def encode_base64(data):
57-
if isinstance(data, _unicode_type):
58-
data = data.encode('utf-8')
5945
encoded = base64.b64encode(data)
6046
return encoded.decode('utf-8')
6147

sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/azure/eventhub/extensions/checkpointstoreblobaio/_vendor/storage/blob/_shared/shared_access_signature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from datetime import date
88

9-
from .parser import _str, _to_utc_datetime
9+
from .parser import _to_utc_datetime
1010
from .constants import X_MS_VERSION
1111
from . import sign_string, url_quote
1212

sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/avro/schema.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,7 @@
2929
import json
3030
import logging
3131
import re
32-
import sys
33-
from six import with_metaclass
3432

35-
PY2 = sys.version_info[0] == 2
36-
37-
if PY2:
38-
_str = unicode # pylint: disable=undefined-variable
39-
else:
40-
_str = str
4133

4234
logger = logging.getLogger(__name__)
4335

@@ -140,7 +132,7 @@ class SchemaParseException(AvroException):
140132
"""Error while parsing a JSON schema descriptor."""
141133

142134

143-
class Schema(with_metaclass(abc.ABCMeta, object)):
135+
class Schema(metaclass=abc.ABCMeta):
144136
"""Abstract base class for all Schema classes."""
145137

146138
def __init__(self, data_type, other_props=None):
@@ -154,9 +146,8 @@ def __init__(self, data_type, other_props=None):
154146
raise SchemaParseException('%r is not a valid Avro type.' % data_type)
155147

156148
# All properties of this schema, as a map: property name -> property value
157-
self._props = {}
149+
self._props = {'type': data_type}
158150

159-
self._props['type'] = data_type
160151
self._type = data_type
161152

162153
if other_props:
@@ -222,7 +213,7 @@ def to_json(self, names):
222213
)
223214

224215

225-
class Name(object):
216+
class Name:
226217
"""Representation of an Avro name."""
227218

228219
def __init__(self, name, namespace=None):
@@ -489,9 +480,9 @@ def __init__(
489480
doc:
490481
other_props:
491482
"""
492-
if (not isinstance(name, _str)) or (not name):
483+
if not isinstance(name, str) or not name:
493484
raise SchemaParseException('Invalid record field name: %r.' % name)
494-
if (order is not None) and (order not in VALID_FIELD_SORT_ORDERS):
485+
if order is not None and order not in VALID_FIELD_SORT_ORDERS:
495486
raise SchemaParseException('Invalid record field order: %r.' % order)
496487

497488
# All properties of this record field:
@@ -564,8 +555,8 @@ def to_json(self, names=None):
564555
return to_dump
565556

566557
def __eq__(self, that):
567-
to_cmp = json.loads(_str(self))
568-
return to_cmp == json.loads(_str(that))
558+
to_cmp = json.loads(str(self))
559+
return to_cmp == json.loads(str(that))
569560

570561

571562
# ------------------------------------------------------------------------------
@@ -679,7 +670,7 @@ def __init__(
679670
symbols = tuple(symbols)
680671
symbol_set = frozenset(symbols)
681672
if (len(symbol_set) != len(symbols)
682-
or not all(map(lambda symbol: isinstance(symbol, _str), symbols))):
673+
or not all(map(lambda symbol: isinstance(symbol, str), symbols))):
683674
raise AvroException(
684675
'Invalid symbols for enum schema: %r.' % (symbols,))
685676

@@ -747,8 +738,8 @@ def to_json(self, names=None):
747738
return to_dump
748739

749740
def __eq__(self, that):
750-
to_cmp = json.loads(_str(self))
751-
return to_cmp == json.loads(_str(that))
741+
to_cmp = json.loads(str(self))
742+
return to_cmp == json.loads(str(that))
752743

753744

754745
# ------------------------------------------------------------------------------
@@ -784,8 +775,8 @@ def to_json(self, names=None):
784775
return to_dump
785776

786777
def __eq__(self, that):
787-
to_cmp = json.loads(_str(self))
788-
return to_cmp == json.loads(_str(that))
778+
to_cmp = json.loads(str(self))
779+
return to_cmp == json.loads(str(that))
789780

790781

791782
# ------------------------------------------------------------------------------
@@ -841,8 +832,8 @@ def to_json(self, names=None):
841832
return to_dump
842833

843834
def __eq__(self, that):
844-
to_cmp = json.loads(_str(self))
845-
return to_cmp == json.loads(_str(that))
835+
to_cmp = json.loads(str(self))
836+
return to_cmp == json.loads(str(that))
846837

847838

848839
# ------------------------------------------------------------------------------
@@ -1031,8 +1022,8 @@ def to_json(self, names=None):
10311022
return to_dump
10321023

10331024
def __eq__(self, that):
1034-
to_cmp = json.loads(_str(self))
1035-
return to_cmp == json.loads(_str(that))
1025+
to_cmp = json.loads(str(self))
1026+
return to_cmp == json.loads(str(that))
10361027

10371028

10381029
# ------------------------------------------------------------------------------
@@ -1164,7 +1155,7 @@ def MakeFields(names):
11641155

11651156
# Parsers for the JSON data types:
11661157
_JSONDataParserTypeMap = {
1167-
_str: _schema_from_json_string,
1158+
str: _schema_from_json_string,
11681159
list: _schema_from_json_array,
11691160
dict: _schema_from_json_object,
11701161
}

sdk/eventhub/azure-eventhub-checkpointstoreblob/azure/eventhub/extensions/checkpointstoreblob/_vendor/storage/blob/_shared/policies.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,13 @@
1414
import uuid
1515
import types
1616
from typing import Any, TYPE_CHECKING
17+
from urllib.parse import (
18+
urlparse,
19+
parse_qsl,
20+
urlunparse,
21+
urlencode,
22+
)
1723
from wsgiref.handlers import format_date_time
18-
try:
19-
from urllib.parse import (
20-
urlparse,
21-
parse_qsl,
22-
urlunparse,
23-
urlencode,
24-
)
25-
except ImportError:
26-
from urllib import urlencode # type: ignore
27-
from urlparse import ( # type: ignore
28-
urlparse,
29-
parse_qsl,
30-
urlunparse,
31-
)
3224

3325
from azure.core.pipeline.policies import (
3426
HeadersPolicy,
@@ -41,10 +33,6 @@
4133

4234
from .models import LocationMode
4335

44-
try:
45-
_unicode_type = unicode # type: ignore
46-
except NameError:
47-
_unicode_type = str
4836

4937
if TYPE_CHECKING:
5038
from azure.core.pipeline import PipelineRequest, PipelineResponse
@@ -54,8 +42,6 @@
5442

5543

5644
def encode_base64(data):
57-
if isinstance(data, _unicode_type):
58-
data = data.encode('utf-8')
5945
encoded = base64.b64encode(data)
6046
return encoded.decode('utf-8')
6147

sdk/ml/azure-ai-ml/tests/internal_utils/unittests/test_ml_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
22
import os
3+
from unittest import mock
34
from unittest.mock import Mock, patch
45

5-
import mock
66
import pytest
77
from test_utilities.constants import Test_Resource_Group, Test_Subscription
88

0 commit comments

Comments
 (0)