]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-27718: Fix help for the signal module (GH-30063)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 13 Dec 2021 09:21:55 +0000 (11:21 +0200)
committerGitHub <noreply@github.com>
Mon, 13 Dec 2021 09:21:55 +0000 (11:21 +0200)
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__.

Lib/signal.py
Lib/test/test_signal.py
Misc/NEWS.d/next/Library/2021-12-11-22-51-30.bpo-27718.MgQiGl.rst [new file with mode: 0644]

index d4a6d6fe2ada8b096a11c9f069efbc7e0ac9a6fd..50b215b29d2fadf6ccc38e860242d04e5d946fb5 100644 (file)
@@ -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 @@ if 'pthread_sigmask' in _globals:
     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 @@ if 'sigwait' in _globals:
     def sigwait(sigset):
         retsig = _signal.sigwait(sigset)
         return _int_to_enum(retsig, Signals)
-    sigwait.__doc__ = _signal.sigwait
 
 
 if 'valid_signals' in _globals:
index daecf196fa1461c7d42035f7c44c6b41d3c60efd..3f0e7270eb26fd191f7fb7e801022237346b74ca 100644 (file)
@@ -1,5 +1,6 @@
 import enum
 import errno
+import inspect
 import os
 import random
 import signal
@@ -60,6 +61,14 @@ class GenericTests(unittest.TestCase):
                     )
             enum._test_simple_enum(CheckedSigmasks, Sigmasks)
 
+    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 (file)
index 0000000..c68e98f
--- /dev/null
@@ -0,0 +1,2 @@
+Fix help for the :mod:`signal` module. Some functions (e.g. ``signal()`` and
+``getsignal()``) were omitted.