@@ -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 ):
@@ -2362,24 +2382,33 @@ def setUpClass(cls):
23622382 def test_slot_wrappers (self ):
23632383 rch , sch = interpreters .channels .create ()
23642384
2365- # For now it's sufficient to check int.__str__.
2366- # See https://github.com/python/cpython/issues/117482
2367- # and https://github.com/python/cpython/pull/117660.
2368- script = textwrap .dedent ('''
2369- text = repr(int.__str__)
2370- sch.send_nowait(text)
2371- ''' )
2385+ slots = []
2386+ script = ''
2387+ for cls in iter_builtin_types ():
2388+ for slot in iter_own_slot_wrappers (cls ):
2389+ slots .append ((cls , slot ))
2390+ script += textwrap .dedent (f"""
2391+ text = repr({ cls .__name__ } .{ slot } )
2392+ sch.send_nowait(({ cls .__name__ !r} , { slot !r} , text))
2393+ """ )
23722394
23732395 exec (script )
2374- expected = rch .recv ()
2396+ all_expected = []
2397+ for cls , slot in slots :
2398+ result = rch .recv ()
2399+ assert result == (cls .__name__ , slot , result [2 ]), (cls , slot , result )
2400+ all_expected .append (result )
23752401
23762402 interp = interpreters .create ()
23772403 interp .exec ('from test.support import interpreters' )
23782404 interp .prepare_main (sch = sch )
23792405 interp .exec (script )
2380- results = rch .recv ()
23812406
2382- self .assertEqual (results , expected )
2407+ for i , _ in enumerate (slots ):
2408+ with self .subTest (cls = cls , slot = slot ):
2409+ expected = all_expected [i ]
2410+ result = rch .recv ()
2411+ self .assertEqual (result , expected )
23832412
23842413
23852414if __name__ == '__main__' :
0 commit comments