@@ -6474,7 +6474,7 @@ def __len__(self):
6474
6474
return 0
6475
6475
6476
6476
self .assertEqual (len (MMC ()), 0 )
6477
- assert callable (MMC .update )
6477
+ self . assertTrue ( callable (MMC .update ) )
6478
6478
self .assertIsInstance (MMC (), typing .Mapping )
6479
6479
6480
6480
class MMB (typing .MutableMapping [KT , VT ]):
@@ -6669,8 +6669,8 @@ def foo(a: A) -> Optional[BaseException]:
6669
6669
else :
6670
6670
return a ()
6671
6671
6672
- assert isinstance (foo (KeyboardInterrupt ), KeyboardInterrupt )
6673
- assert foo (None ) is None
6672
+ self . assertIsInstance (foo (KeyboardInterrupt ), KeyboardInterrupt )
6673
+ self . assertIsNone ( foo (None ))
6674
6674
6675
6675
6676
6676
class TestModules (TestCase ):
@@ -7017,6 +7017,10 @@ def test_basics_functional_syntax(self):
7017
7017
self .assertEqual (Emp .__bases__ , (dict ,))
7018
7018
self .assertEqual (Emp .__annotations__ , {'name' : str , 'id' : int })
7019
7019
self .assertEqual (Emp .__total__ , True )
7020
+ self .assertEqual (Emp .__required_keys__ , {'name' , 'id' })
7021
+ self .assertIsInstance (Emp .__required_keys__ , frozenset )
7022
+ self .assertEqual (Emp .__optional_keys__ , set ())
7023
+ self .assertIsInstance (Emp .__optional_keys__ , frozenset )
7020
7024
7021
7025
def test_typeddict_create_errors (self ):
7022
7026
with self .assertRaises (TypeError ):
@@ -7092,7 +7096,9 @@ def test_total(self):
7092
7096
self .assertEqual (D (x = 1 ), {'x' : 1 })
7093
7097
self .assertEqual (D .__total__ , False )
7094
7098
self .assertEqual (D .__required_keys__ , frozenset ())
7099
+ self .assertIsInstance (D .__required_keys__ , frozenset )
7095
7100
self .assertEqual (D .__optional_keys__ , {'x' })
7101
+ self .assertIsInstance (D .__optional_keys__ , frozenset )
7096
7102
7097
7103
self .assertEqual (Options (), {})
7098
7104
self .assertEqual (Options (log_level = 2 ), {'log_level' : 2 })
@@ -7104,8 +7110,10 @@ def test_optional_keys(self):
7104
7110
class Point2Dor3D (Point2D , total = False ):
7105
7111
z : int
7106
7112
7107
- assert Point2Dor3D .__required_keys__ == frozenset (['x' , 'y' ])
7108
- assert Point2Dor3D .__optional_keys__ == frozenset (['z' ])
7113
+ self .assertEqual (Point2Dor3D .__required_keys__ , frozenset (['x' , 'y' ]))
7114
+ self .assertIsInstance (Point2Dor3D .__required_keys__ , frozenset )
7115
+ self .assertEqual (Point2Dor3D .__optional_keys__ , frozenset (['z' ]))
7116
+ self .assertIsInstance (Point2Dor3D .__optional_keys__ , frozenset )
7109
7117
7110
7118
def test_keys_inheritance (self ):
7111
7119
class BaseAnimal (TypedDict ):
@@ -7118,26 +7126,26 @@ class Animal(BaseAnimal, total=False):
7118
7126
class Cat (Animal ):
7119
7127
fur_color : str
7120
7128
7121
- assert BaseAnimal .__required_keys__ == frozenset (['name' ])
7122
- assert BaseAnimal .__optional_keys__ == frozenset ([])
7123
- assert BaseAnimal .__annotations__ == {'name' : str }
7129
+ self . assertEqual ( BaseAnimal .__required_keys__ , frozenset (['name' ]) )
7130
+ self . assertEqual ( BaseAnimal .__optional_keys__ , frozenset ([]) )
7131
+ self . assertEqual ( BaseAnimal .__annotations__ , {'name' : str })
7124
7132
7125
- assert Animal .__required_keys__ == frozenset (['name' ])
7126
- assert Animal .__optional_keys__ == frozenset (['tail' , 'voice' ])
7127
- assert Animal .__annotations__ == {
7133
+ self . assertEqual ( Animal .__required_keys__ , frozenset (['name' ]) )
7134
+ self . assertEqual ( Animal .__optional_keys__ , frozenset (['tail' , 'voice' ]) )
7135
+ self . assertEqual ( Animal .__annotations__ , {
7128
7136
'name' : str ,
7129
7137
'tail' : bool ,
7130
7138
'voice' : str ,
7131
- }
7139
+ })
7132
7140
7133
- assert Cat .__required_keys__ == frozenset (['name' , 'fur_color' ])
7134
- assert Cat .__optional_keys__ == frozenset (['tail' , 'voice' ])
7135
- assert Cat .__annotations__ == {
7141
+ self . assertEqual ( Cat .__required_keys__ , frozenset (['name' , 'fur_color' ]) )
7142
+ self . assertEqual ( Cat .__optional_keys__ , frozenset (['tail' , 'voice' ]) )
7143
+ self . assertEqual ( Cat .__annotations__ , {
7136
7144
'fur_color' : str ,
7137
7145
'name' : str ,
7138
7146
'tail' : bool ,
7139
7147
'voice' : str ,
7140
- }
7148
+ })
7141
7149
7142
7150
def test_required_notrequired_keys (self ):
7143
7151
self .assertEqual (NontotalMovie .__required_keys__ ,
@@ -7367,11 +7375,11 @@ class C(B[int]):
7367
7375
self .assertEqual (C .__total__ , True )
7368
7376
self .assertEqual (C .__optional_keys__ , frozenset (['b' ]))
7369
7377
self .assertEqual (C .__required_keys__ , frozenset (['a' , 'c' ]))
7370
- assert C .__annotations__ == {
7378
+ self . assertEqual ( C .__annotations__ , {
7371
7379
'a' : T ,
7372
7380
'b' : KT ,
7373
7381
'c' : int ,
7374
- }
7382
+ })
7375
7383
with self .assertRaises (TypeError ):
7376
7384
C [str ]
7377
7385
@@ -7386,11 +7394,11 @@ class Point3D(Point2DGeneric[T], Generic[T, KT]):
7386
7394
self .assertEqual (Point3D .__total__ , True )
7387
7395
self .assertEqual (Point3D .__optional_keys__ , frozenset ())
7388
7396
self .assertEqual (Point3D .__required_keys__ , frozenset (['a' , 'b' , 'c' ]))
7389
- assert Point3D .__annotations__ == {
7397
+ self . assertEqual ( Point3D .__annotations__ , {
7390
7398
'a' : T ,
7391
7399
'b' : T ,
7392
7400
'c' : KT ,
7393
- }
7401
+ })
7394
7402
self .assertEqual (Point3D [int , str ].__origin__ , Point3D )
7395
7403
7396
7404
with self .assertRaises (TypeError ):
@@ -7417,11 +7425,11 @@ class WithImplicitAny(B):
7417
7425
self .assertEqual (WithImplicitAny .__total__ , True )
7418
7426
self .assertEqual (WithImplicitAny .__optional_keys__ , frozenset (['b' ]))
7419
7427
self .assertEqual (WithImplicitAny .__required_keys__ , frozenset (['a' , 'c' ]))
7420
- assert WithImplicitAny .__annotations__ == {
7428
+ self . assertEqual ( WithImplicitAny .__annotations__ , {
7421
7429
'a' : T ,
7422
7430
'b' : KT ,
7423
7431
'c' : int ,
7424
- }
7432
+ })
7425
7433
with self .assertRaises (TypeError ):
7426
7434
WithImplicitAny [str ]
7427
7435
0 commit comments