@@ -1111,147 +1111,6 @@ class Data(_testcapi.ObjExtraData):
11111111        del  d .extra 
11121112        self .assertIsNone (d .extra )
11131113
1114-     def  test_get_type_name (self ):
1115-         class  MyType :
1116-             pass 
1117- 
1118-         from  _testcapi  import  (
1119-             get_type_name , get_type_qualname ,
1120-             get_type_fullyqualname , get_type_module_name )
1121- 
1122-         from  collections  import  OrderedDict 
1123-         ht  =  _testcapi .get_heaptype_for_name ()
1124-         for  cls , fullname , modname , qualname , name  in  (
1125-             (int ,
1126-              'int' ,
1127-              'builtins' ,
1128-              'int' ,
1129-              'int' ),
1130-             (OrderedDict ,
1131-              'collections.OrderedDict' ,
1132-              'collections' ,
1133-              'OrderedDict' ,
1134-              'OrderedDict' ),
1135-             (ht ,
1136-              '_testcapi.HeapTypeNameType' ,
1137-              '_testcapi' ,
1138-              'HeapTypeNameType' ,
1139-              'HeapTypeNameType' ),
1140-             (MyType ,
1141-              f'{ __name__ }  ,
1142-              __name__ ,
1143-              'CAPITest.test_get_type_name.<locals>.MyType' ,
1144-              'MyType' ),
1145-         ):
1146-             with  self .subTest (cls = repr (cls )):
1147-                 self .assertEqual (get_type_fullyqualname (cls ), fullname )
1148-                 self .assertEqual (get_type_module_name (cls ), modname )
1149-                 self .assertEqual (get_type_qualname (cls ), qualname )
1150-                 self .assertEqual (get_type_name (cls ), name )
1151- 
1152-         # override __module__ 
1153-         ht .__module__  =  'test_module' 
1154-         self .assertEqual (get_type_fullyqualname (ht ), 'test_module.HeapTypeNameType' )
1155-         self .assertEqual (get_type_module_name (ht ), 'test_module' )
1156-         self .assertEqual (get_type_qualname (ht ), 'HeapTypeNameType' )
1157-         self .assertEqual (get_type_name (ht ), 'HeapTypeNameType' )
1158- 
1159-         # override __name__ and __qualname__ 
1160-         MyType .__name__  =  'my_name' 
1161-         MyType .__qualname__  =  'my_qualname' 
1162-         self .assertEqual (get_type_fullyqualname (MyType ), f'{ __name__ }  )
1163-         self .assertEqual (get_type_module_name (MyType ), __name__ )
1164-         self .assertEqual (get_type_qualname (MyType ), 'my_qualname' )
1165-         self .assertEqual (get_type_name (MyType ), 'my_name' )
1166- 
1167-         # override also __module__ 
1168-         MyType .__module__  =  'my_module' 
1169-         self .assertEqual (get_type_fullyqualname (MyType ), 'my_module.my_qualname' )
1170-         self .assertEqual (get_type_module_name (MyType ), 'my_module' )
1171-         self .assertEqual (get_type_qualname (MyType ), 'my_qualname' )
1172-         self .assertEqual (get_type_name (MyType ), 'my_name' )
1173- 
1174-         # PyType_GetFullyQualifiedName() ignores the module if it's "builtins" 
1175-         # or "__main__" of it is not a string 
1176-         MyType .__module__  =  'builtins' 
1177-         self .assertEqual (get_type_fullyqualname (MyType ), 'my_qualname' )
1178-         MyType .__module__  =  '__main__' 
1179-         self .assertEqual (get_type_fullyqualname (MyType ), 'my_qualname' )
1180-         MyType .__module__  =  123 
1181-         self .assertEqual (get_type_fullyqualname (MyType ), 'my_qualname' )
1182- 
1183-     def  test_get_base_by_token (self ):
1184-         def  get_base_by_token (src , key , comparable = True ):
1185-             def  run (use_mro ):
1186-                 find_first  =  _testcapi .pytype_getbasebytoken 
1187-                 ret1 , result  =  find_first (src , key , use_mro , True )
1188-                 ret2 , no_result  =  find_first (src , key , use_mro , False )
1189-                 self .assertIn (ret1 , (0 , 1 ))
1190-                 self .assertEqual (ret1 , result  is  not None )
1191-                 self .assertEqual (ret1 , ret2 )
1192-                 self .assertIsNone (no_result )
1193-                 return  result 
1194- 
1195-             found_in_mro  =  run (True )
1196-             found_in_bases  =  run (False )
1197-             if  comparable :
1198-                 self .assertIs (found_in_mro , found_in_bases )
1199-                 return  found_in_mro 
1200-             return  found_in_mro , found_in_bases 
1201- 
1202-         create_type  =  _testcapi .create_type_with_token 
1203-         get_token  =  _testcapi .get_tp_token 
1204- 
1205-         Py_TP_USE_SPEC  =  _testcapi .Py_TP_USE_SPEC 
1206-         self .assertEqual (Py_TP_USE_SPEC , 0 )
1207- 
1208-         A1  =  create_type ('_testcapi.A1' , Py_TP_USE_SPEC )
1209-         self .assertTrue (get_token (A1 ) !=  Py_TP_USE_SPEC )
1210- 
1211-         B1  =  create_type ('_testcapi.B1' , id (self ))
1212-         self .assertTrue (get_token (B1 ) ==  id (self ))
1213- 
1214-         tokenA1  =  get_token (A1 )
1215-         # find A1 from A1 
1216-         found  =  get_base_by_token (A1 , tokenA1 )
1217-         self .assertIs (found , A1 )
1218- 
1219-         # no token in static types 
1220-         STATIC  =  type (1 )
1221-         self .assertEqual (get_token (STATIC ), 0 )
1222-         found  =  get_base_by_token (STATIC , tokenA1 )
1223-         self .assertIs (found , None )
1224- 
1225-         # no token in pure subtypes 
1226-         class  A2 (A1 ): pass 
1227-         self .assertEqual (get_token (A2 ), 0 )
1228-         # find A1 
1229-         class  Z (STATIC , B1 , A2 ): pass 
1230-         found  =  get_base_by_token (Z , tokenA1 )
1231-         self .assertIs (found , A1 )
1232- 
1233-         # searching for NULL token is an error 
1234-         with  self .assertRaises (SystemError ):
1235-             get_base_by_token (Z , 0 )
1236-         with  self .assertRaises (SystemError ):
1237-             get_base_by_token (STATIC , 0 )
1238- 
1239-         # share the token with A1 
1240-         C1  =  create_type ('_testcapi.C1' , tokenA1 )
1241-         self .assertTrue (get_token (C1 ) ==  tokenA1 )
1242- 
1243-         # find C1 first by shared token 
1244-         class  Z (C1 , A2 ): pass 
1245-         found  =  get_base_by_token (Z , tokenA1 )
1246-         self .assertIs (found , C1 )
1247-         # B1 not found 
1248-         found  =  get_base_by_token (Z , get_token (B1 ))
1249-         self .assertIs (found , None )
1250- 
1251-         with  self .assertRaises (TypeError ):
1252-             _testcapi .pytype_getbasebytoken (
1253-                 'not a type' , id (self ), True , False )
1254- 
12551114    def  test_gen_get_code (self ):
12561115        def  genf (): yield 
12571116        gen  =  genf ()
@@ -2922,39 +2781,6 @@ def test_linked_lifecycle_link_incref_unlink_decref(self):
29222781            0 , get_refcount (interpid ))
29232782
29242783
2925- class  BuiltinStaticTypesTests (unittest .TestCase ):
2926- 
2927-     TYPES  =  [
2928-         object ,
2929-         type ,
2930-         int ,
2931-         str ,
2932-         dict ,
2933-         type (None ),
2934-         bool ,
2935-         BaseException ,
2936-         Exception ,
2937-         Warning ,
2938-         DeprecationWarning ,  # Warning subclass 
2939-     ]
2940- 
2941-     def  test_tp_bases_is_set (self ):
2942-         # PyTypeObject.tp_bases is documented as public API. 
2943-         # See https://github.com/python/cpython/issues/105020. 
2944-         for  typeobj  in  self .TYPES :
2945-             with  self .subTest (typeobj ):
2946-                 bases  =  _testcapi .type_get_tp_bases (typeobj )
2947-                 self .assertIsNot (bases , None )
2948- 
2949-     def  test_tp_mro_is_set (self ):
2950-         # PyTypeObject.tp_bases is documented as public API. 
2951-         # See https://github.com/python/cpython/issues/105020. 
2952-         for  typeobj  in  self .TYPES :
2953-             with  self .subTest (typeobj ):
2954-                 mro  =  _testcapi .type_get_tp_mro (typeobj )
2955-                 self .assertIsNot (mro , None )
2956- 
2957- 
29582784class  TestStaticTypes (unittest .TestCase ):
29592785
29602786    _has_run  =  False 
0 commit comments