@@ -7804,58 +7804,54 @@ class A(Generic[T, P, U]): ...
78047804 self .assertEqual (A [float , [range ], int ].__args__ , (float , (range ,), int ))
78057805
78067806
7807- class NoDefaultTests ( BaseTestCase ) :
7807+ class TypedDictSentinelMixin :
78087808 @skip_if_py313_beta_1
78097809 def test_pickling (self ):
78107810 for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
7811- s = pickle .dumps (NoDefault , proto )
7811+ s = pickle .dumps (self . sentinel_type , proto )
78127812 loaded = pickle .loads (s )
7813- self .assertIs (NoDefault , loaded )
7813+ self .assertIs (self . sentinel_type , loaded )
78147814
78157815 @skip_if_py313_beta_1
78167816 def test_doc (self ):
7817- self .assertIsInstance (NoDefault .__doc__ , str )
7817+ self .assertIsInstance (self . sentinel_type .__doc__ , str )
78187818
78197819 def test_constructor (self ):
7820- self .assertIs (NoDefault , type (NoDefault )())
7820+ self .assertIs (self . sentinel_type , type (self . sentinel_type )())
78217821 with self .assertRaises (TypeError ):
7822- type (NoDefault )(1 )
7823-
7824- def test_repr (self ):
7825- self .assertRegex (repr (NoDefault ), r'typing(_extensions)?\.NoDefault' )
7822+ type (self .sentinel_type )(1 )
78267823
78277824 def test_no_call (self ):
78287825 with self .assertRaises (TypeError ):
7829- NoDefault ()
7826+ self . sentinel_type ()
78307827
78317828 @skip_if_py313_beta_1
78327829 def test_immutable (self ):
78337830 with self .assertRaises (AttributeError ):
7834- NoDefault .foo = 'bar'
7831+ self . sentinel_type .foo = 'bar'
78357832 with self .assertRaises (AttributeError ):
7836- NoDefault .foo
7833+ self . sentinel_type .foo
78377834
78387835 # TypeError is consistent with the behavior of NoneType
78397836 with self .assertRaises (TypeError ):
7840- type(NoDefault ).foo = 3
7837+ type(self . sentinel_type ).foo = 3
78417838 with self .assertRaises (AttributeError ):
7842- type (NoDefault ).foo
7839+ type (self . sentinel_type ).foo
78437840
78447841
7845- class NoExtraItemsTests (BaseTestCase ):
7846- def test_pickling (self ):
7847- for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
7848- s = pickle .dumps (NoExtraItems , proto )
7849- loaded = pickle .loads (s )
7850- self .assertIs (NoExtraItems , loaded )
7842+ class NoDefaultTests (TypedDictSentinelMixin , BaseTestCase ):
7843+ sentinel_type = NoDefault
78517844
7852- def test_doc (self ):
7853- self .assertIsInstance (NoExtraItems .__doc__ , str )
7845+ def test_repr (self ):
7846+ if hasattr (typing , 'NoDefault' ):
7847+ mod_name = 'typing'
7848+ else :
7849+ mod_name = "typing_extensions"
7850+ self .assertEqual (repr (NoDefault ), f"{ mod_name } .NoDefault" )
78547851
7855- def test_constructor (self ):
7856- self .assertIs (NoExtraItems , type (NoExtraItems )())
7857- with self .assertRaises (TypeError ):
7858- type (NoExtraItems )(1 )
7852+
7853+ class NoExtraItemsTests (TypedDictSentinelMixin , BaseTestCase ):
7854+ sentinel_type = NoExtraItems
78597855
78607856 def test_repr (self ):
78617857 if hasattr (typing , 'NoExtraItems' ):
@@ -7864,22 +7860,6 @@ def test_repr(self):
78647860 mod_name = "typing_extensions"
78657861 self .assertEqual (repr (NoExtraItems ), f"{ mod_name } .NoExtraItems" )
78667862
7867- def test_no_call (self ):
7868- with self .assertRaises (TypeError ):
7869- NoExtraItems ()
7870-
7871- def test_immutable (self ):
7872- with self .assertRaises (AttributeError ):
7873- NoExtraItems .foo = 'bar'
7874- with self .assertRaises (AttributeError ):
7875- NoExtraItems .foo
7876-
7877- # TypeError is consistent with the behavior of NoneType
7878- with self .assertRaises (TypeError ):
7879- type(NoExtraItems ).foo = 3
7880- with self .assertRaises (AttributeError ):
7881- type (NoExtraItems ).foo
7882-
78837863
78847864class TypeVarInferVarianceTests (BaseTestCase ):
78857865 def test_typevar (self ):
0 commit comments