Skip to content

Commit

Permalink
Remove direct usage of six from project (#3478)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcepl authored Nov 4, 2022
1 parent c134256 commit e2d0e64
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 47 deletions.
19 changes: 6 additions & 13 deletions boto3/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,15 @@
import socket
import warnings

from botocore.vendored import six
from boto3.exceptions import PythonDeprecationWarning

if six.PY3:
# In python3, socket.error is OSError, which is too general
# for what we want (i.e FileNotFoundError is a subclass of OSError).
# In py3 all the socket related errors are in a newly created
# ConnectionError
SOCKET_ERROR = ConnectionError
else:
SOCKET_ERROR = socket.error
# In python3, socket.error is OSError, which is too general
# for what we want (i.e FileNotFoundError is a subclass of OSError).
# In py3 all the socket related errors are in a newly created
# ConnectionError
SOCKET_ERROR = ConnectionError

if six.PY3:
import collections.abc as collections_abc
else:
import collections as collections_abc
import collections.abc as collections_abc


if sys.platform.startswith('win'):
Expand Down
7 changes: 4 additions & 3 deletions boto3/dynamodb/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import collections.abc
from decimal import (
Clamped,
Context,
Expand All @@ -21,6 +20,8 @@
Underflow,
)

from boto3.compat import collections_abc

STRING = 'S'
NUMBER = 'N'
BINARY = 'B'
Expand Down Expand Up @@ -183,7 +184,7 @@ def _is_binary(self, value):
return False

def _is_set(self, value):
if isinstance(value, collections.abc.Set):
if isinstance(value, collections_abc.Set):
return True
return False

Expand All @@ -194,7 +195,7 @@ def _is_type_set(self, value, type_validator):
return False

def _is_map(self, value):
if isinstance(value, collections.abc.Mapping):
if isinstance(value, collections_abc.Mapping):
return True
return False

Expand Down
11 changes: 6 additions & 5 deletions tests/functional/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import io

import botocore
import botocore.stub
import pytest
from botocore.compat import six
from botocore.config import Config
from botocore.stub import Stubber

Expand Down Expand Up @@ -244,7 +245,7 @@ def progress_callback(amount):
class TestUploadFileobj(BaseTransferTest):
def setUp(self):
super().setUp()
self.contents = six.BytesIO(b'foo\n')
self.contents = io.BytesIO(b'foo\n')

def stub_put_object(self):
put_object_response = {
Expand Down Expand Up @@ -330,7 +331,7 @@ def test_object_upload(self):

def test_multipart_upload(self):
chunksize = 8 * (1024**2)
contents = six.BytesIO(b'0' * (chunksize * 3))
contents = io.BytesIO(b'0' * (chunksize * 3))
self.stub_multipart_upload(num_parts=3)
transfer_config = TransferConfig(
multipart_chunksize=chunksize,
Expand All @@ -354,7 +355,7 @@ class TestDownloadFileobj(BaseTransferTest):
def setUp(self):
super().setUp()
self.contents = b'foo'
self.fileobj = six.BytesIO()
self.fileobj = io.BytesIO()

def stub_single_part_download(self):
self.stub_head(content_length=len(self.contents))
Expand Down Expand Up @@ -400,7 +401,7 @@ def stub_get_object(self, full_contents, start_byte=0, end_byte=None):
"ETag": self.etag,
"ContentLength": len(contents),
"ContentType": "binary/octet-stream",
"Body": six.BytesIO(contents),
"Body": io.BytesIO(contents),
"ResponseMetadata": {"HTTPStatusCode": 200},
}
)
Expand Down
11 changes: 5 additions & 6 deletions tests/integration/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# language governing permissions and limitations under the License.
import datetime
import hashlib
import io
import logging
import math
import os
Expand All @@ -21,13 +22,11 @@
import threading

from botocore.client import Config
from botocore.compat import six

import boto3.s3.transfer
import boto3.session
from tests import unique_id, unittest

urlopen = six.moves.urllib.request.urlopen
LOG = logging.getLogger('boto3.tests.integration')


Expand Down Expand Up @@ -338,7 +337,7 @@ def test_copy(self):
self.object_exists('bar')

def test_upload_fileobj(self):
fileobj = six.BytesIO(b'foo')
fileobj = io.BytesIO(b'foo')
self.client.upload_fileobj(
Fileobj=fileobj, Bucket=self.bucket_name, Key='foo'
)
Expand All @@ -356,7 +355,7 @@ def test_upload_fileobj_progress(self):
multipart_threshold=chunksize,
max_concurrency=1,
)
fileobj = six.BytesIO(b'0' * (chunksize * 3))
fileobj = io.BytesIO(b'0' * (chunksize * 3))

def progress_callback(amount):
self.progress += amount
Expand All @@ -374,7 +373,7 @@ def progress_callback(amount):
self.assertEqual(self.progress, chunksize * 3)

def test_download_fileobj(self):
fileobj = six.BytesIO()
fileobj = io.BytesIO()
self.client.put_object(
Bucket=self.bucket_name, Key='foo', Body=b'beach'
)
Expand Down Expand Up @@ -692,7 +691,7 @@ def test_transfer_methods_do_not_use_threads(self):
self.addCleanup(self.delete_object, key)
self.assertTrue(self.object_exists(key))

fileobj = six.BytesIO()
fileobj = io.BytesIO()
self.client.download_fileobj(
Bucket=self.bucket_name, Key='foo', Fileobj=fileobj, Config=config
)
Expand Down
30 changes: 15 additions & 15 deletions tests/unit/docs/test_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from botocore.compat import six
import io

from tests import mock
from tests.unit.docs import BaseDocsTest


class TestResourceDocstrings(BaseDocsTest):
def test_action_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.sample_operation)
action_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand Down Expand Up @@ -51,7 +51,7 @@ def test_action_help(self):

def test_load_help(self):
sub_resource = self.resource.Sample('Id')
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(sub_resource.load)
load_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -69,7 +69,7 @@ def test_load_help(self):
)

def test_sub_resource_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.Sample)
sub_resource_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -85,15 +85,15 @@ def test_sub_resource_help(self):
)

def test_attribute_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.Sample('id').__class__.foo)
attribute_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[' - *(string) --* Documents Foo'], attribute_docstring
)

def test_identifier_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.Sample('id').__class__.name)
identifier_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -106,7 +106,7 @@ def test_identifier_help(self):

def test_reference_help(self):
sample_resource = self.resource.Sample('id')
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(sample_resource.__class__.related_sample)
reference_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -118,7 +118,7 @@ def test_reference_help(self):
)

def test_collection_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.__class__.samples)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -127,7 +127,7 @@ def test_collection_help(self):
)

def test_collection_all_method_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.all)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -146,7 +146,7 @@ def test_collection_all_method_help(self):
)

def test_collection_filter_method_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.filter)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -168,7 +168,7 @@ def test_collection_filter_method_help(self):
)

def test_collection_limit_method_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.limit)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -190,7 +190,7 @@ def test_collection_limit_method_help(self):
)

def test_collection_page_size_method_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.page_size)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -213,7 +213,7 @@ def test_collection_page_size_method_help(self):

def test_collection_chaining_help(self):
collection = self.resource.samples.all()
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(collection.all)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand All @@ -232,7 +232,7 @@ def test_collection_chaining_help(self):
)

def test_batch_action_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.operate)
batch_action_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand Down Expand Up @@ -264,7 +264,7 @@ def test_batch_action_help(self):
)

def test_resource_waiter_help(self):
with mock.patch('sys.stdout', six.StringIO()) as mock_stdout:
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.Sample('id').wait_until_complete)
resource_waiter_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/s3/test_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import io

import pytest
from botocore.compat import six
from botocore.exceptions import ClientError

from boto3.s3 import inject
Expand Down Expand Up @@ -158,7 +159,7 @@ def test_copy(self):
)

def test_upload_fileobj(self):
fileobj = six.BytesIO(b'foo')
fileobj = io.BytesIO(b'foo')
inject.bucket_upload_fileobj(self.bucket, Key='key', Fileobj=fileobj)
self.bucket.meta.client.upload_fileobj.assert_called_with(
Bucket=self.bucket.name,
Expand All @@ -170,7 +171,7 @@ def test_upload_fileobj(self):
)

def test_download_fileobj(self):
obj = six.BytesIO()
obj = io.BytesIO()
inject.bucket_download_fileobj(self.bucket, Key='key', Fileobj=obj)
self.bucket.meta.client.download_fileobj.assert_called_with(
Bucket=self.bucket.name,
Expand Down Expand Up @@ -222,7 +223,7 @@ def test_copy(self):
)

def test_upload_fileobj(self):
fileobj = six.BytesIO(b'foo')
fileobj = io.BytesIO(b'foo')
inject.object_upload_fileobj(self.obj, Fileobj=fileobj)
self.obj.meta.client.upload_fileobj.assert_called_with(
Bucket=self.obj.bucket_name,
Expand All @@ -234,7 +235,7 @@ def test_upload_fileobj(self):
)

def test_download_fileobj(self):
fileobj = six.BytesIO()
fileobj = io.BytesIO()
inject.object_download_fileobj(self.obj, Fileobj=fileobj)
self.obj.meta.client.download_fileobj.assert_called_with(
Bucket=self.obj.bucket_name,
Expand Down

0 comments on commit e2d0e64

Please sign in to comment.