Skip to content

Commit e55deaa

Browse files
[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 e08c0d8)
1 parent 7da9025 commit e55deaa

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Lib/signal.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import _signal
22
from _signal import *
3-
from functools import wraps as _wraps
43
from enum import IntEnum as _IntEnum
54

65
_globals = globals()
@@ -42,6 +41,16 @@ def _enum_to_int(value):
4241
return value
4342

4443

44+
# Similar to functools.wraps(), but only assign __doc__.
45+
# __module__ should be preserved,
46+
# __name__ and __qualname__ are already fine,
47+
# __annotations__ is not set.
48+
def _wraps(wrapped):
49+
def decorator(wrapper):
50+
wrapper.__doc__ = wrapped.__doc__
51+
return wrapper
52+
return decorator
53+
4554
@_wraps(_signal.signal)
4655
def signal(signalnum, handler):
4756
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
@@ -59,7 +68,6 @@ def getsignal(signalnum):
5968
def pthread_sigmask(how, mask):
6069
sigs_set = _signal.pthread_sigmask(how, mask)
6170
return set(_int_to_enum(x, Signals) for x in sigs_set)
62-
pthread_sigmask.__doc__ = _signal.pthread_sigmask.__doc__
6371

6472

6573
if 'sigpending' in _globals:
@@ -73,7 +81,6 @@ def sigpending():
7381
def sigwait(sigset):
7482
retsig = _signal.sigwait(sigset)
7583
return _int_to_enum(retsig, Signals)
76-
sigwait.__doc__ = _signal.sigwait
7784

7885

7986
if 'valid_signals' in _globals:

Lib/test/test_signal.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import errno
2+
import inspect
23
import os
34
import random
45
import signal
@@ -33,6 +34,14 @@ def test_enums(self):
3334
self.assertIsInstance(sig, signal.Signals)
3435
self.assertEqual(sys.platform, "win32")
3536

37+
def test_functions_module_attr(self):
38+
# Issue #27718: If __all__ is not defined all non-builtin functions
39+
# should have correct __module__ to be displayed by pydoc.
40+
for name in dir(signal):
41+
value = getattr(signal, name)
42+
if inspect.isroutine(value) and not inspect.isbuiltin(value):
43+
self.assertEqual(value.__module__, 'signal')
44+
3645

3746
@unittest.skipIf(sys.platform == "win32", "Not valid on Windows")
3847
class PosixTests(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix help for the :mod:`signal` module. Some functions (e.g. ``signal()`` and
2+
``getsignal()``) were omitted.

0 commit comments

Comments
 (0)