mitogen.utils: Preserve docstring of functions decorated @with_router

Co-authored-by: Rezart Qelibari <gast-kontakt+mitogen@astzweig.de>

Replaces #837
Fixes #836
pull/922/head
Alex Willmer 3 years ago
parent a743e831c6
commit e101cc4f44

@ -24,6 +24,7 @@ v0.3.3.dev0
* :gh:issue:`906` Support packages dynamically inserted into sys.modules, e.g. `distro` >= 1.7.0 as `ansible.module_utils.distro`.
* :gh:issue:`918` Support Python 3.10
* :gh:issue:`920` Support Ansible :ans:conn:`~podman` connection plugin
* :gh:issue:`836` :func:`mitogen.utils.with_router` decorator preserves the docstring in addition to the name.
v0.3.2 (2022-01-12)

@ -29,6 +29,7 @@
# !mitogen: minify_safe
import datetime
import functools
import logging
import os
import sys
@ -171,12 +172,9 @@ def with_router(func):
do_stuff(blah, 123)
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
return run_with_router(func, *args, **kwargs)
if mitogen.core.PY3:
wrapper.func_name = func.__name__
else:
wrapper.func_name = func.func_name
return wrapper

@ -12,6 +12,7 @@ def func0(router):
@mitogen.utils.with_router
def func(router):
"Docstring of func"
return router
@ -31,6 +32,10 @@ class WithRouterTest(testlib.TestCase):
self.assertIsInstance(router, mitogen.master.Router)
self.assertFalse(testlib.threading__thread_is_alive(router.broker._thread))
def test_with_broker_preserves_attributes(self):
self.assertEqual(func.__doc__, 'Docstring of func')
self.assertEqual(func.__name__, 'func')
class Dict(dict): pass
class List(list): pass

Loading…
Cancel
Save