88import re
99import sys
1010import warnings
11+ from test .support .import_helper import import_fresh_module
1112from unittest import TestCase , main , skipUnless , skip
1213from unittest .mock import patch
1314from copy import copy , deepcopy
@@ -3908,7 +3909,14 @@ class MyChain(typing.ChainMap[str, T]): ...
39083909 self .assertEqual (MyChain [int ]().__orig_class__ , MyChain [int ])
39093910
39103911 def test_all_repr_eq_any (self ):
3911- objs = (getattr (typing , el ) for el in typing .__all__ )
3912+ typing = import_fresh_module ("typing" )
3913+ with warnings .catch_warnings (record = True ) as wlog :
3914+ warnings .filterwarnings ('always' , '' , DeprecationWarning )
3915+ objs = [getattr (typing , el ) for el in typing .__all__ ]
3916+ self .assertEqual (
3917+ [str (w .message ) for w in wlog ],
3918+ ["'typing.ByteString' is deprecated and slated for removal in Python 3.14" ]
3919+ )
39123920 for obj in objs :
39133921 self .assertNotEqual (repr (obj ), '' )
39143922 self .assertEqual (obj , obj )
@@ -5996,8 +6004,16 @@ def test_mutablesequence(self):
59966004 self .assertNotIsInstance ((), typing .MutableSequence )
59976005
59986006 def test_bytestring (self ):
5999- self .assertIsInstance (b'' , typing .ByteString )
6000- self .assertIsInstance (bytearray (b'' ), typing .ByteString )
6007+ with self .assertWarns (DeprecationWarning ):
6008+ from typing import ByteString
6009+ with self .assertWarns (DeprecationWarning ):
6010+ self .assertIsInstance (b'' , ByteString )
6011+ with self .assertWarns (DeprecationWarning ):
6012+ self .assertIsInstance (bytearray (b'' ), ByteString )
6013+ with self .assertWarns (DeprecationWarning ):
6014+ class Foo (ByteString ): ...
6015+ with self .assertWarns (DeprecationWarning ):
6016+ class Bar (ByteString , typing .Awaitable ): ...
60016017
60026018 def test_list (self ):
60036019 self .assertIsSubclass (list , typing .List )
@@ -8293,6 +8309,10 @@ def test_no_isinstance(self):
82938309class SpecialAttrsTests (BaseTestCase ):
82948310
82958311 def test_special_attrs (self ):
8312+ with warnings .catch_warnings (
8313+ action = 'ignore' , category = DeprecationWarning
8314+ ):
8315+ typing_ByteString = typing .ByteString
82968316 cls_to_check = {
82978317 # ABC classes
82988318 typing .AbstractSet : 'AbstractSet' ,
@@ -8301,7 +8321,7 @@ def test_special_attrs(self):
83018321 typing .AsyncIterable : 'AsyncIterable' ,
83028322 typing .AsyncIterator : 'AsyncIterator' ,
83038323 typing .Awaitable : 'Awaitable' ,
8304- typing . ByteString : 'ByteString' ,
8324+ typing_ByteString : 'ByteString' ,
83058325 typing .Callable : 'Callable' ,
83068326 typing .ChainMap : 'ChainMap' ,
83078327 typing .Collection : 'Collection' ,
@@ -8626,6 +8646,8 @@ def test_all_exported_names(self):
86268646 getattr (v , '__module__' , None ) == typing .__name__
86278647 )
86288648 }
8649+ # Deprecated; added dynamically via module __getattr__
8650+ computed_all .add ("ByteString" )
86298651 self .assertSetEqual (computed_all , actual_all )
86308652
86318653
0 commit comments