Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changes/next-release/enhancement-Deprecation-17508.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "enhancement",
"category": "Deprecation",
"description": "Importing the six module from botocore.compat or botocore.vendored will now raise a deprecation warning. The module will be removed in a future release. Users should add the module as a direct dependency if it's still needed."
}
19 changes: 18 additions & 1 deletion botocore/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import shlex
import re
import os
import warnings
from collections import OrderedDict
from collections.abc import MutableMapping
from math import floor

from botocore.vendored import six
from botocore.exceptions import MD5UnavailableError
from dateutil.tz import tzlocal
from urllib3 import exceptions
Expand Down Expand Up @@ -360,3 +360,20 @@ def has_minimum_crt_version(minimum_version):
HAS_GZIP = True
except ImportError:
HAS_GZIP = False


def __getattr__(name):
"""
Module override to raise warnings when deprecated libraries
are imported in external code.
"""
if name == "six":
warnstr = (
"The botocore.compat.six module is deprecated and will be removed "
"in a future version. Please use six as a direct dependency."
)
warnings.warn(warnstr, DeprecationWarning, stacklevel=2)
from botocore.vendored import six
return six

raise AttributeError(f"Module {__name__} has no attribute {name}.")
7 changes: 7 additions & 0 deletions botocore/vendored/six.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
import operator
import sys
import types
import warnings

warnstr = (
"The botocore.vendored.six module is deprecated and will be removed "
"in a future version. Please use six as a direct dependency."
)
warnings.warn(warnstr, DeprecationWarning, stacklevel=2)

__author__ = "Benjamin Peterson <[email protected]>"
__version__ = "1.16.0"
Expand Down
62 changes: 0 additions & 62 deletions tests/functional/test_six_threading.py

This file was deleted.

25 changes: 25 additions & 0 deletions tests/unit/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import datetime
import warnings

import pytest

Expand Down Expand Up @@ -225,3 +226,27 @@ def test_has_crt_global(self):
assert HAS_CRT
except ImportError:
assert not HAS_CRT


@pytest.mark.filterwarnings("always::DeprecationWarning")
def test_six_deprecation_warning():
vendored_msg = "The botocore.vendored.six module is deprecated"
compat_msg = "The botocore.compat.six module is deprecated"

# Verify import from vendored raises a warning
with pytest.warns(DeprecationWarning, match=vendored_msg):
import botocore.vendored.six # noqa: F401

# Verify import from compat raises a warning
with pytest.warns(DeprecationWarning, match=compat_msg):
from botocore.compat import six # noqa: F401

# Verify other imports don't raise a warning
with warnings.catch_warnings():
warnings.simplefilter("error")
from botocore.compat import urlparse # noqa: F401

# Verify direct import of the module doesn't raise a warning
with warnings.catch_warnings():
warnings.simplefilter("error")
import botocore.compat # noqa: F401