diff options
author | Yilei Yang <yileiyang@google.com> | 2023-12-24 01:07:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-24 01:07:52 (GMT) |
commit | 050783cb37d6a09d8238fa640814df8a915f6a68 (patch) | |
tree | 7560dc77405b33a58cd7fccd6f0f74c49a083591 /Lib/test/test_signal.py | |
parent | 0187a7e4ec9550a6e35dd06b26f22863520242ab (diff) | |
download | cpython-050783cb37d6a09d8238fa640814df8a915f6a68.zip cpython-050783cb37d6a09d8238fa640814df8a915f6a68.tar.gz cpython-050783cb37d6a09d8238fa640814df8a915f6a68.tar.bz2 |
gh-112559: Avoid unnecessary conversion attempts to enum_klass in signal.py (#113040)
Diffstat (limited to 'Lib/test/test_signal.py')
-rw-r--r-- | Lib/test/test_signal.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index acb7e9d..637a0ca 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -1,5 +1,6 @@ import enum import errno +import functools import inspect import os import random @@ -76,6 +77,9 @@ class PosixTests(unittest.TestCase): def trivial_signal_handler(self, *args): pass + def create_handler_with_partial(self, argument): + return functools.partial(self.trivial_signal_handler, argument) + def test_out_of_range_signal_number_raises_error(self): self.assertRaises(ValueError, signal.getsignal, 4242) @@ -96,6 +100,28 @@ class PosixTests(unittest.TestCase): signal.signal(signal.SIGHUP, hup) self.assertEqual(signal.getsignal(signal.SIGHUP), hup) + def test_no_repr_is_called_on_signal_handler(self): + # See https://github.com/python/cpython/issues/112559. + + class MyArgument: + def __init__(self): + self.repr_count = 0 + + def __repr__(self): + self.repr_count += 1 + return super().__repr__() + + argument = MyArgument() + self.assertEqual(0, argument.repr_count) + + handler = self.create_handler_with_partial(argument) + hup = signal.signal(signal.SIGHUP, handler) + self.assertIsInstance(hup, signal.Handlers) + self.assertEqual(signal.getsignal(signal.SIGHUP), handler) + signal.signal(signal.SIGHUP, hup) + self.assertEqual(signal.getsignal(signal.SIGHUP), hup) + self.assertEqual(0, argument.repr_count) + def test_strsignal(self): self.assertIn("Interrupt", signal.strsignal(signal.SIGINT)) self.assertIn("Terminated", signal.strsignal(signal.SIGTERM)) |