11import enum
22import errno
3+ import functools
34import inspect
45import os
56import random
@@ -76,6 +77,9 @@ class PosixTests(unittest.TestCase):
7677 def trivial_signal_handler (self , * args ):
7778 pass
7879
80+ def create_handler_with_partial (self , argument ):
81+ return functools .partial (self .trivial_signal_handler , argument )
82+
7983 def test_out_of_range_signal_number_raises_error (self ):
8084 self .assertRaises (ValueError , signal .getsignal , 4242 )
8185
@@ -96,6 +100,28 @@ def test_getsignal(self):
96100 signal .signal (signal .SIGHUP , hup )
97101 self .assertEqual (signal .getsignal (signal .SIGHUP ), hup )
98102
103+ def test_no_repr_is_called_on_signal_handler (self ):
104+ # See https://github.com/python/cpython/issues/112559.
105+
106+ class MyArgument :
107+ def __init__ (self ):
108+ self .repr_count = 0
109+
110+ def __repr__ (self ):
111+ self .repr_count += 1
112+ return super ().__repr__ ()
113+
114+ argument = MyArgument ()
115+ self .assertEqual (0 , argument .repr_count )
116+
117+ handler = self .create_handler_with_partial (argument )
118+ hup = signal .signal (signal .SIGHUP , handler )
119+ self .assertIsInstance (hup , signal .Handlers )
120+ self .assertEqual (signal .getsignal (signal .SIGHUP ), handler )
121+ signal .signal (signal .SIGHUP , hup )
122+ self .assertEqual (signal .getsignal (signal .SIGHUP ), hup )
123+ self .assertEqual (0 , argument .repr_count )
124+
99125 def test_strsignal (self ):
100126 self .assertIn ("Interrupt" , signal .strsignal (signal .SIGINT ))
101127 self .assertIn ("Terminated" , signal .strsignal (signal .SIGTERM ))
0 commit comments