Fix #6709: autodoc: mock object does not work as a class decorator

This commit is contained in:
Takeshi KOMIYA 2019-10-06 23:31:07 +09:00
parent 73a93f897e
commit 59336da8bd
3 changed files with 23 additions and 1 deletions

View File

@ -24,6 +24,7 @@ Bugs fixed
.. _latex3/latex2e#173: https://github.com/latex3/latex2e/issues/173
* #6618: LaTeX: Avoid section names at the end of a page
* #6709: autodoc: mock object does not work as a class decorator
Testing
--------

View File

@ -60,7 +60,7 @@ class _MockObject:
return _make_subclass(key, self.__display_name__, self.__class__)()
def __call__(self, *args, **kw) -> Any:
if args and type(args[0]) in [FunctionType, MethodType]:
if args and type(args[0]) in [type, FunctionType, MethodType]:
# Appears to be a decorator, pass through unchanged
return args[0]
return self

View File

@ -96,3 +96,24 @@ def test_abc_MockObject():
assert isinstance(obj, Base)
assert isinstance(obj, _MockObject)
assert isinstance(obj.some_method(), Derived)
def test_mock_decorator():
mock = _MockObject()
@mock.function_deco
def func():
"""docstring"""
class Foo:
@mock.method_deco
def meth(self):
"""docstring"""
@mock.class_deco
class Bar:
"""docstring"""
assert func.__doc__ == "docstring"
assert Foo.meth.__doc__ == "docstring"
assert Bar.__doc__ == "docstring"