Repository: sphinx-doc/sphinx

Issue:
Updating sphinx from 1.8.0 to 1.8.1 results in warning
Previously posted in forum: https://groups.google.com/d/msg/sphinx-users/C1JJH62UMaM/AigXvOC-CQAJ

**Describe the bug**
After the updating sphinx from 1.8.0 to 1.8.1 building of the docs print these warnings:

```shell
WARNING: error while formatting arguments for eg.TriggerEvent: 'function' object has no attribute '__bases__'
WARNING: error while formatting arguments for eg.PrintError: 'function' object has no attribute '__bases__'
```

**To Reproduce**
Steps to reproduce the behavior (Windows only):
```
$ git clone https://github.com/EventGhost/EventGhost
$ cd EventGhost\_build\data
$ sphinx-build -b html docs tmp
```

**Expected behavior**
A sphinx build run without errors.


**Your project**
https://github.com/EventGhost/EventGhost
https://github.com/EventGhost/EventGhost/tree/master/_build/data/docs


**Environment info**
- OS: Windows
- Python version: 2.7.15
- Sphinx version: 1.8.1
- Sphinx extensions: sphinx.ext.autodoc


**Additional context**

> [Komiya Takeshi wrote](https://groups.google.com/d/msg/sphinx-users/C1JJH62UMaM/GmpgG9otFwAJ)
>I think that might be related with this change.
https://github.com/sphinx-doc/sphinx/compare/sphinx-doc:16533cf...sphinx-doc:65a560f#diff-48ca4d6544b092f35d729127500bff5fR1058


Discussion:

Patch:
diff --git a/CHANGES b/CHANGES
index ea1301c7c..65f39e538 100644
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,7 @@ Bugs fixed
 * #6026: LaTeX: A cross reference to definition list does not work
 * #6046: LaTeX: ``TypeError`` is raised when invalid latex_elements given
 * #6019: imgconverter: Including multipage PDF fails
+* #6047: autodoc: ``autofunction`` emits a warning for method objects
 
 Testing
 --------
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index df3319695..1b1635faa 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -1056,6 +1056,7 @@ def format_args(self):
             return None
         try:
             if (not isfunction(self.object) and
+                    not inspect.ismethod(self.object) and
                     not isbuiltin(self.object) and
                     not inspect.isclass(self.object) and
                     hasattr(self.object, '__call__')):


Test patch:
diff --git a/tests/roots/test-ext-autodoc/target/callable.py b/tests/roots/test-ext-autodoc/target/callable.py
index f3358eafd..6fcd5053e 100644
--- a/tests/roots/test-ext-autodoc/target/callable.py
+++ b/tests/roots/test-ext-autodoc/target/callable.py
@@ -4,5 +4,10 @@ class Callable():
     def __call__(self, arg1, arg2, **kwargs):
         pass
 
+    def method(self, arg1, arg2):
+        """docstring of Callable.method()."""
+        pass
+
 
 function = Callable()
+method = function.method
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py
index 1be35eb5b..7b1384bf7 100644
--- a/tests/test_autodoc.py
+++ b/tests/test_autodoc.py
@@ -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')
 def test_mocked_module_imports(app):
     options = {"members": 'TestAutodoc,decoratedFunction'}