Repository: sphinx-doc/sphinx

Issue:
WARNING: error while formatting arguments for example.call: '_Any' object has no attribute '__origin__'
### Problem
- Since 1.7.6, an AttributeError is raised.
- This was added on #5300.

```
WARNING: error while formatting arguments for example.call: '_Any' object has no attribute '__origin__'
```

#### Procedure to reproduce the problem

```
.. autofunction:: example.call
```
```
def call(self, func_name: str, *args) -> Any:
    pass
```

#### Error logs / results
```
WARNING: error while formatting arguments for example.call: '_Any' object has no attribute '__origin__'
```

#### Expected results
Succeeded.

### Environment info
- OS: Mac
- Python version: 3.6
- Sphinx version: 1.7.7


Discussion:

Patch:
diff --git a/CHANGES b/CHANGES
index 144b1ea13..f0ca4f51f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,7 @@ Bugs fixed
 
 * #5320: intersphinx: crashed if invalid url given
 * #5326: manpage: crashed when invalid docname is specified as ``man_pages``
+* #5322: autodoc: ``Any`` typehint causes formatting error
 
 Testing
 --------
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 3b5d48e2a..bab88eb88 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -531,8 +531,10 @@ def format_annotation_old(self, annotation):
                 qualname = annotation.__qualname__
             elif getattr(annotation, '__forward_arg__', None):
                 qualname = annotation.__forward_arg__
-            else:
+            elif getattr(annotation, '__origin__', None):
                 qualname = self.format_annotation(annotation.__origin__)  # ex. Union
+            else:
+                qualname = repr(annotation).replace('typing.', '')
         elif hasattr(annotation, '__qualname__'):
             qualname = '%s.%s' % (module, annotation.__qualname__)
         else:


Test patch:
diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py
index a48aedcf0..928a45621 100644
--- a/tests/test_util_inspect.py
+++ b/tests/test_util_inspect.py
@@ -232,7 +232,7 @@ def meth2(self, arg1, arg2):
                     reason='type annotation test is available on py34 or above')
 def test_Signature_annotations():
     from typing_test_data import (
-        f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, Node)
+        f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, Node)
 
     # Class annotations
     sig = inspect.Signature(f0).format_args()
@@ -293,6 +293,10 @@ def test_Signature_annotations():
     sig = inspect.Signature(f13).format_args()
     assert sig == '() -> Optional[str]'
 
+    # Any
+    sig = inspect.Signature(f14).format_args()
+    assert sig == '() -> Any'
+
     # type hints by string
     sig = inspect.Signature(Node.children).format_args()
     assert sig == '(self) -> List[typing_test_data.Node]'
diff --git a/tests/typing_test_data.py b/tests/typing_test_data.py
index 5b161eac4..4dc2d06f5 100644
--- a/tests/typing_test_data.py
+++ b/tests/typing_test_data.py
@@ -1,5 +1,5 @@
 from numbers import Integral
-from typing import List, TypeVar, Union, Callable, Tuple, Optional
+from typing import Any, List, TypeVar, Union, Callable, Tuple, Optional
 
 
 def f0(x: int, y: Integral) -> None:
@@ -72,6 +72,10 @@ def f13() -> Optional[str]:
     pass
 
 
+def f14() -> Any:
+    pass
+
+
 class Node:
     def __init__(self, parent: Optional['Node']) -> None:
         pass