8
8
import re
9
9
import sys
10
10
import warnings
11
+ from test .support .import_helper import import_fresh_module
11
12
from unittest import TestCase , main , skipUnless , skip
12
13
from unittest .mock import patch
13
14
from copy import copy , deepcopy
@@ -3908,7 +3909,14 @@ class MyChain(typing.ChainMap[str, T]): ...
3908
3909
self .assertEqual (MyChain [int ]().__orig_class__ , MyChain [int ])
3909
3910
3910
3911
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
+ )
3912
3920
for obj in objs :
3913
3921
self .assertNotEqual (repr (obj ), '' )
3914
3922
self .assertEqual (obj , obj )
@@ -5996,8 +6004,16 @@ def test_mutablesequence(self):
5996
6004
self .assertNotIsInstance ((), typing .MutableSequence )
5997
6005
5998
6006
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 ): ...
6001
6017
6002
6018
def test_list (self ):
6003
6019
self .assertIsSubclass (list , typing .List )
@@ -8293,6 +8309,10 @@ def test_no_isinstance(self):
8293
8309
class SpecialAttrsTests (BaseTestCase ):
8294
8310
8295
8311
def test_special_attrs (self ):
8312
+ with warnings .catch_warnings (
8313
+ action = 'ignore' , category = DeprecationWarning
8314
+ ):
8315
+ typing_ByteString = typing .ByteString
8296
8316
cls_to_check = {
8297
8317
# ABC classes
8298
8318
typing .AbstractSet : 'AbstractSet' ,
@@ -8301,7 +8321,7 @@ def test_special_attrs(self):
8301
8321
typing .AsyncIterable : 'AsyncIterable' ,
8302
8322
typing .AsyncIterator : 'AsyncIterator' ,
8303
8323
typing .Awaitable : 'Awaitable' ,
8304
- typing . ByteString : 'ByteString' ,
8324
+ typing_ByteString : 'ByteString' ,
8305
8325
typing .Callable : 'Callable' ,
8306
8326
typing .ChainMap : 'ChainMap' ,
8307
8327
typing .Collection : 'Collection' ,
@@ -8626,6 +8646,8 @@ def test_all_exported_names(self):
8626
8646
getattr (v , '__module__' , None ) == typing .__name__
8627
8647
)
8628
8648
}
8649
+ # Deprecated; added dynamically via module __getattr__
8650
+ computed_all .add ("ByteString" )
8629
8651
self .assertSetEqual (computed_all , actual_all )
8630
8652
8631
8653
0 commit comments