Skip to content

Commit 3440079

Browse files
committed
Add official warnings for the removal of six from vendoring
1 parent f354b72 commit 3440079

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

botocore/compat.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import shlex
2323
import re
2424
import os
25+
import warnings
2526
from collections import OrderedDict
2627
from collections.abc import MutableMapping
2728
from math import floor
2829

29-
from botocore.vendored import six
3030
from botocore.exceptions import MD5UnavailableError
3131
from dateutil.tz import tzlocal
3232
from urllib3 import exceptions
@@ -360,3 +360,20 @@ def has_minimum_crt_version(minimum_version):
360360
HAS_GZIP = True
361361
except ImportError:
362362
HAS_GZIP = False
363+
364+
365+
def __getattr__(name):
366+
"""
367+
Module override to raise warnings when deprecated libraries
368+
are imported in external code.
369+
"""
370+
if name == "six":
371+
warnstr = (
372+
"The botocore.compat.six module is deprecated and will be removed "
373+
"in a future version. Please use six as a direct dependency."
374+
)
375+
warnings.warn(warnstr, DeprecationWarning, stacklevel=2)
376+
from botocore.vendored import six
377+
return six
378+
379+
raise AttributeError(f"Module {__name__} has no attribute {name}.")

botocore/vendored/six.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
import operator
2828
import sys
2929
import types
30+
import warnings
31+
32+
warnstr = (
33+
"The botocore.vendored.six module is deprecated and will be removed "
34+
"in a future version. Please use six as a direct dependency."
35+
)
36+
warnings.warn(warnstr, DeprecationWarning, stacklevel=2)
3037

3138
__author__ = "Benjamin Peterson <[email protected]>"
3239
__version__ = "1.16.0"

tests/functional/test_six_threading.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import sys
66
import threading
77
import time
8+
import warnings
89

9-
from botocore.vendored import six
1010
from tests import mock
1111

12+
with warnings.catch_warnings():
13+
from botocore.vendored import six
14+
1215
_original_setattr = six.moves.__class__.__setattr__
1316

1417

tests/unit/test_compat.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
import datetime
14+
import warnings
1415

1516
import pytest
1617

@@ -225,3 +226,27 @@ def test_has_crt_global(self):
225226
assert HAS_CRT
226227
except ImportError:
227228
assert not HAS_CRT
229+
230+
231+
@pytest.mark.filterwarnings("always::DeprecationWarning")
232+
def test_six_deprecation_warning():
233+
vendored_msg = "The botocore.vendored.six module is deprecated"
234+
compat_msg = "The botocore.compat.six module is deprecated"
235+
236+
# Verify import from compat raises a warning
237+
with pytest.warns(DeprecationWarning, match=vendored_msg):
238+
import botocore.vendored.six # noqa: F401
239+
240+
# Verify import from compat raises a warning
241+
with pytest.warns(DeprecationWarning, match=compat_msg):
242+
from botocore.compat import six # noqa: F401
243+
244+
# Verify other imports don't raise a warning
245+
with warnings.catch_warnings():
246+
warnings.simplefilter("error")
247+
from botocore.compat import urlparse # noqa: F401
248+
249+
# Verify direct import of the module doesn't raise a warning
250+
with warnings.catch_warnings():
251+
warnings.simplefilter("error")
252+
import botocore.compat # noqa: F401

0 commit comments

Comments
 (0)