gh-91896: Improve visibility of ByteString deprecation warnings (#104294)

This commit is contained in:
Alex Waygood 2023-05-12 07:01:31 +01:00 committed by GitHub
parent a0a98ddb31
commit f0f5bb3204
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 12 deletions

View file

@ -11,6 +11,7 @@ from itertools import product, chain, combinations
import string
import sys
from test import support
from test.support.import_helper import import_fresh_module
import types
import unittest
@ -25,7 +26,7 @@ from collections.abc import Sized, Container, Callable, Collection
from collections.abc import Set, MutableSet
from collections.abc import Mapping, MutableMapping, KeysView, ItemsView, ValuesView
from collections.abc import Sequence, MutableSequence
from collections.abc import ByteString, Buffer
from collections.abc import Buffer
class TestUserObjects(unittest.TestCase):
@ -1939,6 +1940,8 @@ class TestCollectionABCs(ABCTestCase):
nativeseq, seqseq, (letter, start, stop))
def test_ByteString(self):
with self.assertWarns(DeprecationWarning):
from collections.abc import ByteString
for sample in [bytes, bytearray]:
with self.assertWarns(DeprecationWarning):
self.assertIsInstance(sample(), ByteString)
@ -1960,6 +1963,11 @@ class TestCollectionABCs(ABCTestCase):
# No metaclass conflict
class Z(ByteString, Awaitable): pass
def test_ByteString_attribute_access(self):
collections_abc = import_fresh_module("collections.abc")
with self.assertWarns(DeprecationWarning):
collections_abc.ByteString
def test_Buffer(self):
for sample in [bytes, bytearray, memoryview]:
self.assertIsInstance(sample(b"x"), Buffer)