@@ -29,6 +29,26 @@ def clear_typing_caches():
2929 f ()
3030
3131
32+ def iter_builtin_types ():
33+ for obj in __builtins__ .values ():
34+ if not isinstance (obj , type ):
35+ continue
36+ cls = obj
37+ if cls .__module__ != 'builtins' :
38+ continue
39+ yield cls
40+
41+
42+ @cpython_only
43+ def iter_own_slot_wrappers (cls ):
44+ for name , value in vars (cls ).items ():
45+ if not name .startswith ('__' ) or not name .endswith ('__' ):
46+ continue
47+ if 'slot wrapper' not in str (value ):
48+ continue
49+ yield name
50+
51+
3252class TypesTests (unittest .TestCase ):
3353
3454 def test_truth_values (self ):
@@ -2361,24 +2381,33 @@ def setUpClass(cls):
23612381 def test_slot_wrappers (self ):
23622382 rch , sch = interpreters .channels .create ()
23632383
2364- # For now it's sufficient to check int.__str__.
2365- # See https://github.com/python/cpython/issues/117482
2366- # and https://github.com/python/cpython/pull/117660.
2367- script = textwrap .dedent ('''
2368- text = repr(int.__str__)
2369- sch.send_nowait(text)
2370- ''' )
2384+ slots = []
2385+ script = ''
2386+ for cls in iter_builtin_types ():
2387+ for slot in iter_own_slot_wrappers (cls ):
2388+ slots .append ((cls , slot ))
2389+ script += textwrap .dedent (f"""
2390+ text = repr({ cls .__name__ } .{ slot } )
2391+ sch.send_nowait(({ cls .__name__ !r} , { slot !r} , text))
2392+ """ )
23712393
23722394 exec (script )
2373- expected = rch .recv ()
2395+ all_expected = []
2396+ for cls , slot in slots :
2397+ result = rch .recv ()
2398+ assert result == (cls .__name__ , slot , result [2 ]), (cls , slot , result )
2399+ all_expected .append (result )
23742400
23752401 interp = interpreters .create ()
23762402 interp .exec ('from test.support import interpreters' )
23772403 interp .prepare_main (sch = sch )
23782404 interp .exec (script )
2379- results = rch .recv ()
23802405
2381- self .assertEqual (results , expected )
2406+ for i , _ in enumerate (slots ):
2407+ with self .subTest (cls = cls , slot = slot ):
2408+ expected = all_expected [i ]
2409+ result = rch .recv ()
2410+ self .assertEqual (result , expected )
23822411
23832412
23842413if __name__ == '__main__' :
0 commit comments