@@ -1340,15 +1340,15 @@ def test_find_class(self):
13401340 r"Can't resolve path 'log\.spam' on module 'math'" ) as cm :
13411341 unpickler4 .find_class ('math' , 'log.spam' )
13421342 self .assertEqual (str (cm .exception .__context__ ),
1343- "'builtin_function_or_method ' object has no attribute 'spam'" )
1343+ "'types.BuiltinFunctionType ' object has no attribute 'spam'" )
13441344 with self .assertRaisesRegex (AttributeError ,
13451345 r"module 'math' has no attribute 'log\.<locals>\.spam'" ):
13461346 unpickler .find_class ('math' , 'log.<locals>.spam' )
13471347 with self .assertRaisesRegex (AttributeError ,
13481348 r"Can't resolve path 'log\.<locals>\.spam' on module 'math'" ) as cm :
13491349 unpickler4 .find_class ('math' , 'log.<locals>.spam' )
13501350 self .assertEqual (str (cm .exception .__context__ ),
1351- "'builtin_function_or_method ' object has no attribute '<locals>'" )
1351+ "'types.BuiltinFunctionType ' object has no attribute '<locals>'" )
13521352 with self .assertRaisesRegex (AttributeError ,
13531353 "module 'math' has no attribute ''" ):
13541354 unpickler .find_class ('math' , '' )
@@ -3301,11 +3301,33 @@ def test_builtin_types(self):
33013301 self .assertIs (self .loads (s ), t )
33023302
33033303 def test_types_types (self ):
3304+ if self .py_version < (3 , 8 ):
3305+ self .skipTest ('not supported in Python < 3.8' )
3306+ # types with __module__ == 'types' added before 3.16
3307+ old_names = {
3308+ 'EllipsisType' : (3 , 8 ),
3309+ 'GenericAlias' : (3 , 9 ),
3310+ 'NoneType' : (3 , 8 ),
3311+ 'NotImplementedType' : (3 , 8 ),
3312+ 'SimpleNamespace' : (3 , 8 ),
3313+ 'Union' : (3 , 8 ),
3314+ 'DynamicClassAttribute' : (3 , 8 ),
3315+ '_GeneratorWrapper' : (3 , 8 ),
3316+ }
3317+ # new types added after 3.16
3318+ new_names = {
3319+ }
33043320 for t in types .__dict__ .values ():
33053321 if isinstance (t , type ):
3322+ if self .py_version < (3 , 16 ):
3323+ if t .__name__ not in old_names or self .py_version < old_names [t .__name__ ]:
3324+ continue
3325+ elif t .__name__ in new_names and self .py_version < new_names [t .__name__ ]:
3326+ continue
33063327 for proto in protocols :
3307- s = self .dumps (t , proto )
3308- self .assertIs (self .loads (s ), t )
3328+ with self .subTest (name = t .__name__ , proto = proto ):
3329+ s = self .dumps (t , proto )
3330+ self .assertIs (self .loads (s ), t )
33093331
33103332 def test_builtin_exceptions (self ):
33113333 new_names = {
0 commit comments