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,23 @@ 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
7509
+ with self .assertWarns (DeprecationWarning ):
7510
+ self .assertIsInstance (b'' , ByteString )
7503
7511
with self .assertWarns (DeprecationWarning ):
7504
- self .assertIsInstance (b'' , typing . ByteString )
7512
+ self .assertIsInstance (bytearray ( b'' ), ByteString )
7505
7513
with self .assertWarns (DeprecationWarning ):
7506
- self .assertIsInstance ( bytearray ( b'' ), typing . ByteString )
7514
+ self .assertIsSubclass ( bytes , ByteString )
7507
7515
with self .assertWarns (DeprecationWarning ):
7508
- class Foo ( typing . ByteString ): ...
7516
+ self . assertIsSubclass ( bytearray , ByteString )
7509
7517
with self .assertWarns (DeprecationWarning ):
7510
- class Bar (typing .ByteString , typing .Awaitable ): ...
7518
+ class Foo (ByteString ): ...
7519
+ with self .assertWarns (DeprecationWarning ):
7520
+ class Bar (ByteString , typing .Awaitable ): ...
7511
7521
7512
7522
def test_list (self ):
7513
7523
self .assertIsSubclass (list , typing .List )
@@ -10455,6 +10465,10 @@ def test_no_isinstance(self):
10455
10465
class SpecialAttrsTests (BaseTestCase ):
10456
10466
10457
10467
def test_special_attrs (self ):
10468
+ with warnings .catch_warnings (
10469
+ action = 'ignore' , category = DeprecationWarning
10470
+ ):
10471
+ typing_ByteString = typing .ByteString
10458
10472
cls_to_check = {
10459
10473
# ABC classes
10460
10474
typing .AbstractSet : 'AbstractSet' ,
@@ -10463,7 +10477,7 @@ def test_special_attrs(self):
10463
10477
typing .AsyncIterable : 'AsyncIterable' ,
10464
10478
typing .AsyncIterator : 'AsyncIterator' ,
10465
10479
typing .Awaitable : 'Awaitable' ,
10466
- typing . ByteString : 'ByteString' ,
10480
+ typing_ByteString : 'ByteString' ,
10467
10481
typing .Callable : 'Callable' ,
10468
10482
typing .ChainMap : 'ChainMap' ,
10469
10483
typing .Collection : 'Collection' ,
@@ -10816,7 +10830,8 @@ def test_all_exported_names(self):
10816
10830
# there's a few types and metaclasses that aren't exported
10817
10831
not k .endswith (('Meta' , '_contra' , '_co' )) and
10818
10832
not k .upper () == k and
10819
- # but export all things that have __module__ == 'typing'
10833
+ k not in {"ByteString" } and
10834
+ # but export all other things that have __module__ == 'typing'
10820
10835
getattr (v , '__module__' , None ) == typing .__name__
10821
10836
)
10822
10837
}
0 commit comments