13
13
import pickle
14
14
import re
15
15
import sys
16
+ import warnings
16
17
from unittest import TestCase , main , skip
17
18
from unittest .mock import patch
18
19
from copy import copy , deepcopy
@@ -7500,14 +7501,19 @@ def test_mutablesequence(self):
7500
7501
self .assertNotIsInstance ((), typing .MutableSequence )
7501
7502
7502
7503
def test_bytestring (self ):
7504
+ previous_typing_module = sys .modules .pop ("typing" , None )
7505
+ self .addCleanup (sys .modules .__setitem__ , "typing" , previous_typing_module )
7506
+
7507
+ with self .assertWarns (DeprecationWarning ):
7508
+ from typing import ByteString
7503
7509
with self .assertWarns (DeprecationWarning ):
7504
- self .assertIsInstance (b'' , typing . ByteString )
7510
+ self .assertIsInstance (b'' , ByteString )
7505
7511
with self .assertWarns (DeprecationWarning ):
7506
- self .assertIsInstance (bytearray (b'' ), typing . ByteString )
7512
+ self .assertIsInstance (bytearray (b'' ), ByteString )
7507
7513
with self .assertWarns (DeprecationWarning ):
7508
- class Foo (typing . ByteString ): ...
7514
+ class Foo (ByteString ): ...
7509
7515
with self .assertWarns (DeprecationWarning ):
7510
- class Bar (typing . ByteString , typing .Awaitable ): ...
7516
+ class Bar (ByteString , typing .Awaitable ): ...
7511
7517
7512
7518
def test_list (self ):
7513
7519
self .assertIsSubclass (list , typing .List )
@@ -10455,6 +10461,10 @@ def test_no_isinstance(self):
10455
10461
class SpecialAttrsTests (BaseTestCase ):
10456
10462
10457
10463
def test_special_attrs (self ):
10464
+ with warnings .catch_warnings (
10465
+ action = 'ignore' , category = DeprecationWarning
10466
+ ):
10467
+ typing_ByteString = typing .ByteString
10458
10468
cls_to_check = {
10459
10469
# ABC classes
10460
10470
typing .AbstractSet : 'AbstractSet' ,
@@ -10463,7 +10473,7 @@ def test_special_attrs(self):
10463
10473
typing .AsyncIterable : 'AsyncIterable' ,
10464
10474
typing .AsyncIterator : 'AsyncIterator' ,
10465
10475
typing .Awaitable : 'Awaitable' ,
10466
- typing . ByteString : 'ByteString' ,
10476
+ typing_ByteString : 'ByteString' ,
10467
10477
typing .Callable : 'Callable' ,
10468
10478
typing .ChainMap : 'ChainMap' ,
10469
10479
typing .Collection : 'Collection' ,
@@ -10816,7 +10826,8 @@ def test_all_exported_names(self):
10816
10826
# there's a few types and metaclasses that aren't exported
10817
10827
not k .endswith (('Meta' , '_contra' , '_co' )) and
10818
10828
not k .upper () == k and
10819
- # but export all things that have __module__ == 'typing'
10829
+ k not in {"ByteString" } and
10830
+ # but export all other things that have __module__ == 'typing'
10820
10831
getattr (v , '__module__' , None ) == typing .__name__
10821
10832
)
10822
10833
}
0 commit comments