Merge pull request #922 from moreati/functools.wraps
mitogen.utils: Preserve docstring of functions decorated @with_router
This commit is contained in:
commit
11a61acb32
|
@ -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:`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:`918` Support Python 3.10
|
||||||
* :gh:issue:`920` Support Ansible :ans:conn:`~podman` connection plugin
|
* :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)
|
v0.3.2 (2022-01-12)
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
# !mitogen: minify_safe
|
# !mitogen: minify_safe
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -171,12 +172,9 @@ def with_router(func):
|
||||||
|
|
||||||
do_stuff(blah, 123)
|
do_stuff(blah, 123)
|
||||||
"""
|
"""
|
||||||
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
return run_with_router(func, *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
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ def func0(router):
|
||||||
|
|
||||||
@mitogen.utils.with_router
|
@mitogen.utils.with_router
|
||||||
def func(router):
|
def func(router):
|
||||||
|
"Docstring of func"
|
||||||
return router
|
return router
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +32,10 @@ class WithRouterTest(testlib.TestCase):
|
||||||
self.assertIsInstance(router, mitogen.master.Router)
|
self.assertIsInstance(router, mitogen.master.Router)
|
||||||
self.assertFalse(testlib.threading__thread_is_alive(router.broker._thread))
|
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 Dict(dict): pass
|
||||||
class List(list): pass
|
class List(list): pass
|
||||||
|
|
Loading…
Reference in New Issue