Skip to content

bpo-27718: Fix help for the signal module #30063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Lib/signal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import _signal
from _signal import *
from functools import wraps as _wraps
from enum import IntEnum as _IntEnum

_globals = globals()
Expand Down Expand Up @@ -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))
Expand All @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_signal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import enum
import errno
import inspect
import os
import random
import signal
Expand Down Expand Up @@ -60,6 +61,14 @@ def test_enums(self):
)
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix help for the :mod:`signal` module. Some functions (e.g. ``signal()`` and
``getsignal()``) were omitted.