[Python-checkins] [3.10] bpo-27718: Fix help for the signal module (GH-30063) (GH-30080)

miss-islington webhook-mailer at python.org
Mon Dec 13 05:43:40 EST 2021


https://github.com/python/cpython/commit/80f98b1614cc8e58d8a5ec72c94d27f663e23035
commit: 80f98b1614cc8e58d8a5ec72c94d27f663e23035
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-12-13T02:43:13-08:00
summary:

[3.10] bpo-27718: Fix help for the signal module (GH-30063) (GH-30080)


Functions signal(), getsignal(), pthread_sigmask(), sigpending(),
sigwait() and valid_signals() were omitted.

If __all__ is not defined all non-builtin functions should have
correct __module__.
(cherry picked from commit e08c0d8eec528f1d7a282ee19bcadb9aae9ec123)
(cherry picked from commit e55deaabd8de338138cf29aea6890996e794c997)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
A Misc/NEWS.d/next/Library/2021-12-11-22-51-30.bpo-27718.MgQiGl.rst
M Lib/signal.py
M Lib/test/test_signal.py

diff --git a/Lib/signal.py b/Lib/signal.py
index d4a6d6fe2ada8..50b215b29d2fa 100644
--- a/Lib/signal.py
+++ b/Lib/signal.py
@@ -1,6 +1,5 @@
 import _signal
 from _signal import *
-from functools import wraps as _wraps
 from enum import IntEnum as _IntEnum
 
 _globals = globals()
@@ -42,6 +41,16 @@ def _enum_to_int(value):
         return value
 
 
+# Similar to functools.wraps(), but only assign __doc__.
+# __module__ should be preserved,
+# __name__ and __qualname__ are already fine,
+# __annotations__ is not set.
+def _wraps(wrapped):
+    def decorator(wrapper):
+        wrapper.__doc__ = wrapped.__doc__
+        return wrapper
+    return decorator
+
 @_wraps(_signal.signal)
 def signal(signalnum, handler):
     handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
@@ -59,7 +68,6 @@ def getsignal(signalnum):
     def pthread_sigmask(how, mask):
         sigs_set = _signal.pthread_sigmask(how, mask)
         return set(_int_to_enum(x, Signals) for x in sigs_set)
-    pthread_sigmask.__doc__ = _signal.pthread_sigmask.__doc__
 
 
 if 'sigpending' in _globals:
@@ -73,7 +81,6 @@ def sigpending():
     def sigwait(sigset):
         retsig = _signal.sigwait(sigset)
         return _int_to_enum(retsig, Signals)
-    sigwait.__doc__ = _signal.sigwait
 
 
 if 'valid_signals' in _globals:
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index f18e72f6fc96b..f91d33271dbb4 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -1,4 +1,5 @@
 import errno
+import inspect
 import os
 import random
 import signal
@@ -32,6 +33,14 @@ def test_enums(self):
                 self.assertIsInstance(sig, signal.Signals)
                 self.assertEqual(sys.platform, "win32")
 
+    def test_functions_module_attr(self):
+        # Issue #27718: If __all__ is not defined all non-builtin functions
+        # should have correct __module__ to be displayed by pydoc.
+        for name in dir(signal):
+            value = getattr(signal, name)
+            if inspect.isroutine(value) and not inspect.isbuiltin(value):
+                self.assertEqual(value.__module__, 'signal')
+
 
 @unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
 class PosixTests(unittest.TestCase):
diff --git a/Misc/NEWS.d/next/Library/2021-12-11-22-51-30.bpo-27718.MgQiGl.rst b/Misc/NEWS.d/next/Library/2021-12-11-22-51-30.bpo-27718.MgQiGl.rst
new file mode 100644
index 0000000000000..c68e98ff0630b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-12-11-22-51-30.bpo-27718.MgQiGl.rst
@@ -0,0 +1,2 @@
+Fix help for the :mod:`signal` module. Some functions (e.g. ``signal()`` and
+``getsignal()``) were omitted.



More information about the Python-checkins mailing list