1313import pickle
1414import re
1515import sys
16+ import warnings
1617from unittest import TestCase , main , skip
1718from unittest .mock import patch
1819from copy import copy , deepcopy
@@ -7500,14 +7501,23 @@ def test_mutablesequence(self):
75007501 self .assertNotIsInstance ((), typing .MutableSequence )
75017502
75027503 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 )
75037511 with self .assertWarns (DeprecationWarning ):
7504- self .assertIsInstance (b'' , typing . ByteString )
7512+ self .assertIsInstance (bytearray ( b'' ), ByteString )
75057513 with self .assertWarns (DeprecationWarning ):
7506- self .assertIsInstance ( bytearray ( b'' ), typing . ByteString )
7514+ self .assertIsSubclass ( bytes , ByteString )
75077515 with self .assertWarns (DeprecationWarning ):
7508- class Foo ( typing . ByteString ): ...
7516+ self . assertIsSubclass ( bytearray , ByteString )
75097517 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 ): ...
75117521
75127522 def test_list (self ):
75137523 self .assertIsSubclass (list , typing .List )
@@ -10455,6 +10465,10 @@ def test_no_isinstance(self):
1045510465class SpecialAttrsTests (BaseTestCase ):
1045610466
1045710467 def test_special_attrs (self ):
10468+ with warnings .catch_warnings (
10469+ action = 'ignore' , category = DeprecationWarning
10470+ ):
10471+ typing_ByteString = typing .ByteString
1045810472 cls_to_check = {
1045910473 # ABC classes
1046010474 typing .AbstractSet : 'AbstractSet' ,
@@ -10463,7 +10477,7 @@ def test_special_attrs(self):
1046310477 typing .AsyncIterable : 'AsyncIterable' ,
1046410478 typing .AsyncIterator : 'AsyncIterator' ,
1046510479 typing .Awaitable : 'Awaitable' ,
10466- typing . ByteString : 'ByteString' ,
10480+ typing_ByteString : 'ByteString' ,
1046710481 typing .Callable : 'Callable' ,
1046810482 typing .ChainMap : 'ChainMap' ,
1046910483 typing .Collection : 'Collection' ,
@@ -10816,7 +10830,8 @@ def test_all_exported_names(self):
1081610830 # there's a few types and metaclasses that aren't exported
1081710831 not k .endswith (('Meta' , '_contra' , '_co' )) and
1081810832 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'
1082010835 getattr (v , '__module__' , None ) == typing .__name__
1082110836 )
1082210837 }
0 commit comments