5050import weakref
5151import types
5252
53- with warnings .catch_warnings ():
54- warnings .simplefilter ("ignore" , DeprecationWarning )
55-
56- from typing import AnyStr
57-
5853from test .support import (
5954 captured_stderr , cpython_only , requires_docstrings , import_helper , run_code ,
6055 subTests , EqualToForwardRef ,
@@ -494,7 +489,6 @@ def test_repr(self):
494489 self .assertEqual (repr (T ), '~T' )
495490 self .assertEqual (repr (KT ), '~KT' )
496491 self .assertEqual (repr (VT ), '~VT' )
497- self .assertEqual (repr (AnyStr ), '~AnyStr' )
498492 T_co = TypeVar ('T_co' , covariant = True )
499493 self .assertEqual (repr (T_co ), '+T_co' )
500494 T_contra = TypeVar ('T_contra' , contravariant = True )
@@ -6393,13 +6387,15 @@ def on_bottom(self, a: int) -> int:
63936387class CastTests (BaseTestCase ):
63946388
63956389 def test_basics (self ):
6390+ T = TypeVar ("T" )
6391+
63966392 self .assertEqual (cast (int , 42 ), 42 )
63976393 self .assertEqual (cast (float , 42 ), 42 )
63986394 self .assertIs (type (cast (float , 42 )), int )
63996395 self .assertEqual (cast (Any , 42 ), 42 )
64006396 self .assertEqual (cast (list , 42 ), 42 )
64016397 self .assertEqual (cast (Union [str , float ], 42 ), 42 )
6402- self .assertEqual (cast (AnyStr , 42 ), 42 )
6398+ self .assertEqual (cast (T , 42 ), 42 )
64036399 self .assertEqual (cast (None , 42 ), 42 )
64046400
64056401 def test_errors (self ):
@@ -6412,9 +6408,10 @@ class AssertTypeTests(BaseTestCase):
64126408
64136409 def test_basics (self ):
64146410 arg = 42
6411+ T = TypeVar ("T" )
64156412 self .assertIs (assert_type (arg , int ), arg )
64166413 self .assertIs (assert_type (arg , str | float ), arg )
6417- self .assertIs (assert_type (arg , AnyStr ), arg )
6414+ self .assertIs (assert_type (arg , T ), arg )
64186415 self .assertIs (assert_type (arg , None ), arg )
64196416
64206417 def test_errors (self ):
@@ -9642,7 +9639,7 @@ def test_no_isinstance(self):
96429639class IOTests (BaseTestCase ):
96439640
96449641 def test_io (self ):
9645- def stuff (a : IO ) -> AnyStr :
9642+ def stuff (a : IO ):
96469643 return a .readline ()
96479644
96489645 a = stuff .__annotations__ ['a' ]
@@ -9651,7 +9648,6 @@ def stuff(a: IO) -> AnyStr:
96519648 self .assertEqual (repr (any_str ), 'AnyStr' )
96529649 self .assertEqual (any_str .__bound__ , None )
96539650 self .assertEqual (any_str .__constraints__ , (bytes , str ))
9654- self .assertEqual (any_str .__constraints__ , AnyStr .__constraints__ )
96559651
96569652 def test_textio (self ):
96579653
@@ -11308,6 +11304,8 @@ def test_any_str_deprecated(self):
1130811304 with self .assertWarnsRegex (DeprecationWarning , r'typing\.AnyStr' ):
1130911305 fresh .AnyStr
1131011306
11307+ self .assertEqual (repr (fresh .AnyStr ), '~AnyStr' )
11308+
1131111309
1131211310class TypeIterationTests (BaseTestCase ):
1131311311 _UNITERABLE_TYPES = (
0 commit comments