Repository: sphinx-doc/sphinx

Issue:
PEP 484 type hints using typing module are awful to read
Subject: PEP 484 type hints using typing module are awful to read

### Problem
- Sphinx's autodoc system currently includes 'typing.' before every single reference to one of that module's members. In pretty much all other cases I'd think this would be desirable, but here it really detracts from the intent of type annotations.
- Problem is only somewhat ugly with individual uses of these hinting tools, but nested ones as shown are terrible.
- I've flailed around google for half an hour and gone through the documentation closely and found nothing about this except #1968 , in which it was commented in passing that this might be too long

#### Procedure to reproduce the problem
```
from typing import Iterable, Sequence
class MyClass:
    def __init__(self, csv_rows: Iterable[Sequence[str]]):
        pass
```

#### Error logs / results
http://i.imgur.com/CmIk5hr.png

#### Expected results
- Same, but without the repeated 'typing.' prefixes
- Possibly a configuration list of modules to ignore when making these prefixes?

### Reproducible project / your project
- Above code should be sufficient?

### Environment info
- OS: Win7
- Python version: 3.5.2
- Sphinx version: 1.4.3? (Whatever's on pypi today)



Discussion:

Patch:
diff --git a/CHANGES b/CHANGES
index 9a435bfd4..39733a6d8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -74,6 +74,7 @@ Features added
   extension to limit the scope of inheritance graphs.
 * #4183: doctest: ``:pyversion:`` option also follows PEP-440 specification
 * #4235: html: Add :confval:`manpages_url` to make manpage roles to hyperlinks
+* #3570: autodoc: Do not display 'typing.' module for type hints
 
 Features removed
 ----------------
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 62cd1a7e9..8c10b7aa5 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -404,10 +404,18 @@ def format_annotation(self, annotation):
         if annotation == Ellipsis:
             return '...'
         if not isinstance(annotation, type):
-            return repr(annotation)
+            qualified_name = repr(annotation)
+            if qualified_name.startswith('typing.'):  # for typing.Union
+                return qualified_name.split('.', 1)[1]
+            else:
+                return qualified_name
 
-        qualified_name = (annotation.__module__ + '.' + annotation.__qualname__  # type: ignore
-                          if annotation else repr(annotation))
+        if not annotation:
+            qualified_name = repr(annotation)
+        elif annotation.__module__ == 'typing':
+            qualified_name = annotation.__qualname__  # type: ignore
+        else:
+            qualified_name = (annotation.__module__ + '.' + annotation.__qualname__)  # type: ignore  # NOQA
 
         if annotation.__module__ == 'builtins':
             return annotation.__qualname__  # type: ignore


Test patch:
diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py
index f0188cafa..b5d50ed71 100644
--- a/tests/test_util_inspect.py
+++ b/tests/test_util_inspect.py
@@ -211,15 +211,15 @@ def test_Signature_annotations():
 
     # Generic types with concrete parameters
     sig = inspect.Signature(f1).format_args()
-    assert sig == '(x: typing.List[int]) -> typing.List[int]'
+    assert sig == '(x: List[int]) -> List[int]'
 
     # TypeVars and generic types with TypeVars
     sig = inspect.Signature(f2).format_args()
-    assert sig == '(x: typing.List[T], y: typing.List[T_co], z: T) -> typing.List[T_contra]'
+    assert sig == '(x: List[T], y: List[T_co], z: T) -> List[T_contra]'
 
     # Union types
     sig = inspect.Signature(f3).format_args()
-    assert sig == '(x: typing.Union[str, numbers.Integral]) -> None'
+    assert sig == '(x: Union[str, numbers.Integral]) -> None'
 
     # Quoted annotations
     sig = inspect.Signature(f4).format_args()
@@ -239,14 +239,14 @@ def test_Signature_annotations():
 
     # Callable types
     sig = inspect.Signature(f8).format_args()
-    assert sig == '(x: typing.Callable[[int, str], int]) -> None'
+    assert sig == '(x: Callable[[int, str], int]) -> None'
 
     sig = inspect.Signature(f9).format_args()
-    assert sig == '(x: typing.Callable) -> None'
+    assert sig == '(x: Callable) -> None'
 
     # Tuple types
     sig = inspect.Signature(f10).format_args()
-    assert sig == '(x: typing.Tuple[int, str], y: typing.Tuple[int, ...]) -> None'
+    assert sig == '(x: Tuple[int, str], y: Tuple[int, ...]) -> None'
 
     # Instance annotations
     sig = inspect.Signature(f11).format_args()