Skip to content

Commit fc787a5

Browse files
committed
improvements
1 parent b508dd0 commit fc787a5

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Lib/_collections_abc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,5 +1168,6 @@ def __getattr__(attr):
11681168
if attr == "ByteString":
11691169
import warnings
11701170
warnings._deprecated("collections.abc.ByteString", remove=(3, 17))
1171+
globals()["ByteString"] = _deprecated_ByteString
11711172
return _deprecated_ByteString
11721173
raise AttributeError(f"module 'collections.abc' has no attribute {attr!r}")

Lib/test/libregrtest/refleak.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def runtest_refleak(test_name, test_func,
9696
# `ByteString` is not included in `collections.abc.__all__`
9797
with warnings.catch_warnings(action='ignore', category=DeprecationWarning):
9898
ByteString = collections.abc.ByteString
99-
for obj in ByteString.__subclasses__() + [ByteString]:
99+
# Mypy doesn't even think `ByteString` is a class, hence the `type: ignore`
100+
for obj in ByteString.__subclasses__() + [ByteString]: # type: ignore[attr-defined]
100101
abcs[obj] = _get_dump(obj)[0]
101102

102103
# bpo-31217: Integer pool to get a single integer object for the same

Lib/test/test_collections.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,12 @@ def assert_index_same(seq1, seq2, index_args):
19361936
nativeseq, seqseq, (letter, start, stop))
19371937

19381938
def test_ByteString(self):
1939+
previous_sys_modules = sys.modules.copy()
1940+
self.addCleanup(sys.modules.update, previous_sys_modules)
1941+
1942+
for module in "collections", "_collections_abc", "collections.abc":
1943+
sys.modules.pop(module, None)
1944+
19391945
with self.assertWarns(DeprecationWarning):
19401946
from collections.abc import ByteString
19411947
for sample in [bytes, bytearray]:

Lib/typing.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3783,7 +3783,14 @@ def __getattr__(attr):
37833783
elif attr == "ByteString":
37843784
import warnings
37853785

3786-
warnings._deprecated("typing.ByteString", remove=(3, 17))
3786+
warnings._deprecated(
3787+
"typing.ByteString",
3788+
message=(
3789+
"{name!r} and 'collections.abc.ByteString' are deprecated "
3790+
"and slated for removal in Python {remove}"
3791+
),
3792+
remove=(3, 17)
3793+
)
37873794

37883795
class _DeprecatedGenericAlias(_SpecialGenericAlias, _root=True):
37893796
def __init__(

0 commit comments

Comments
 (0)