Merge pull request #6083 from tk0miya/6047_autofunction_warns_for_methods

Fix #6047: autodoc: ``autofunction`` emits a warning for method objects
This commit is contained in:
Takeshi KOMIYA 2019-02-17 19:17:07 +09:00 committed by GitHub
commit 836d65f04c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 0 deletions

View File

@ -20,6 +20,7 @@ Bugs fixed
* #6026: LaTeX: A cross reference to definition list does not work * #6026: LaTeX: A cross reference to definition list does not work
* #6046: LaTeX: ``TypeError`` is raised when invalid latex_elements given * #6046: LaTeX: ``TypeError`` is raised when invalid latex_elements given
* #6019: imgconverter: Including multipage PDF fails * #6019: imgconverter: Including multipage PDF fails
* #6047: autodoc: ``autofunction`` emits a warning for method objects
Testing Testing
-------- --------

View File

@ -1056,6 +1056,7 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ
return None return None
try: try:
if (not isfunction(self.object) and if (not isfunction(self.object) and
not inspect.ismethod(self.object) and
not isbuiltin(self.object) and not isbuiltin(self.object) and
not inspect.isclass(self.object) and not inspect.isclass(self.object) and
hasattr(self.object, '__call__')): hasattr(self.object, '__call__')):

View File

@ -4,5 +4,10 @@ class Callable():
def __call__(self, arg1, arg2, **kwargs): def __call__(self, arg1, arg2, **kwargs):
pass pass
def method(self, arg1, arg2):
"""docstring of Callable.method()."""
pass
function = Callable() function = Callable()
method = function.method

View File

@ -1359,6 +1359,19 @@ def test_autofunction_for_callable(app):
] ]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autofunction_for_method(app):
actual = do_autodoc(app, 'function', 'target.callable.method')
assert list(actual) == [
'',
'.. py:function:: method(arg1, arg2)',
' :module: target.callable',
'',
' docstring of Callable.method().',
' '
]
@pytest.mark.sphinx('html', testroot='root') @pytest.mark.sphinx('html', testroot='root')
def test_mocked_module_imports(app): def test_mocked_module_imports(app):
options = {"members": 'TestAutodoc,decoratedFunction'} options = {"members": 'TestAutodoc,decoratedFunction'}