@@ -29,6 +29,26 @@ def clear_typing_caches():
29
29
f ()
30
30
31
31
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
+
32
52
class TypesTests (unittest .TestCase ):
33
53
34
54
def test_truth_values (self ):
@@ -2362,24 +2382,33 @@ def setUpClass(cls):
2362
2382
def test_slot_wrappers (self ):
2363
2383
rch , sch = interpreters .channels .create ()
2364
2384
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
+ """ )
2372
2394
2373
2395
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 )
2375
2401
2376
2402
interp = interpreters .create ()
2377
2403
interp .exec ('from test.support import interpreters' )
2378
2404
interp .prepare_main (sch = sch )
2379
2405
interp .exec (script )
2380
- results = rch .recv ()
2381
2406
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 )
2383
2412
2384
2413
2385
2414
if __name__ == '__main__' :
0 commit comments