Skip to content

Commit 1e217cd

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

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

botocore/compat.py

Lines changed: 21 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,23 @@ 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+
# The vendored copy of six is deprecated and will be removed in a future version.
377+
with warnings.catch_warnings():
378+
warnings.simplefilter("ignore", DeprecationWarning)
379+
from botocore.vendored import six
380+
return six
381+
382+
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/unit/test_compat.py

Lines changed: 20 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,22 @@ def test_has_crt_global(self):
225226
assert HAS_CRT
226227
except ImportError:
227228
assert not HAS_CRT
229+
230+
231+
def test_six_deprecation_warning():
232+
msg = "The botocore.compat.six module is deprecated"
233+
234+
# Verify import from compat raises a warning
235+
with warnings.catch_warnings(record=True) as w1:
236+
from botocore.compat import six
237+
assert any([warning for warning in w1 if msg in str(warning.message)])
238+
239+
# Verify other imports don't raise a warning
240+
with warnings.catch_warnings(record=True) as w2:
241+
from botocore.compat import urlparse
242+
assert not any([warning for warning in w2 if msg in str(warning.message)])
243+
244+
# Verify direct import of the module doesn't raise a warning
245+
with warnings.catch_warnings(record=True) as w3:
246+
import botocore.compat
247+
assert not any([warning for warning in w3 if msg in str(warning.message)])

tests/unit/test_vendored.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
14+
import warnings
15+
16+
def test_six_deprecation_warning():
17+
msg = "The botocore.vendored.six module is deprecated"
18+
19+
# Verify import from vendored.six raises a warning
20+
with warnings.catch_warnings(record=True) as w1:
21+
import botocore.vendored.six
22+
assert any([warning for warning in w1 if msg in str(warning.message)])
23+
24+
# Verify import of other vendored modules don't raise a warning
25+
with warnings.catch_warnings(record=True) as w2:
26+
import botocore.vendored
27+
import botocore.vendored.requests
28+
assert not any([warning for warning in w2 if msg in str(warning.message)])

0 commit comments

Comments
 (0)