File tree Expand file tree Collapse file tree 4 files changed +54
-2
lines changed
Expand file tree Collapse file tree 4 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 2222import shlex
2323import re
2424import os
25+ import warnings
2526from collections import OrderedDict
2627from collections .abc import MutableMapping
2728from math import floor
2829
29- from botocore .vendored import six
3030from botocore .exceptions import MD5UnavailableError
3131from dateutil .tz import tzlocal
3232from urllib3 import exceptions
@@ -360,3 +360,20 @@ def has_minimum_crt_version(minimum_version):
360360 HAS_GZIP = True
361361except 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 } ." )
Original file line number Diff line number Diff line change 2727import operator
2828import sys
2929import 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 <benjamin@python.org>"
3239__version__ = "1.16.0"
Original file line number Diff line number Diff line change 55import sys
66import threading
77import time
8+ import warnings
89
9- from botocore .vendored import six
1010from 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
Original file line number Diff line number Diff line change 1111# ANY KIND, either express or implied. See the License for the specific
1212# language governing permissions and limitations under the License.
1313import datetime
14+ import warnings
1415
1516import 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
You can’t perform that action at this time.
0 commit comments