summaryrefslogtreecommitdiff
path: root/tests/test_autodoc.py
diff options
context:
space:
mode:
authorAndrey Vlasovskikh <andrey.vlasovskikh@gmail.com>2015-07-29 23:10:02 +0300
committerAndrey Vlasovskikh <andrey.vlasovskikh@gmail.com>2015-07-31 21:26:32 +0300
commitdd32b7fdb24d3b4e35f2c09195bcc2dcfc75c792 (patch)
tree288606602507f69cce3f546ed7e9c231156e76f1 /tests/test_autodoc.py
parentf53fb636276ce77384d5612b4e214457e63f193b (diff)
downloadsphinx-git-dd32b7fdb24d3b4e35f2c09195bcc2dcfc75c792.tar.gz
Closes #1968: Show extended type hints for function annotations that use 'typing' module
Diffstat (limited to 'tests/test_autodoc.py')
-rw-r--r--tests/test_autodoc.py46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py
index 2d61edabd..f13a08cff 100644
--- a/tests/test_autodoc.py
+++ b/tests/test_autodoc.py
@@ -11,8 +11,9 @@
"""
# "raises" imported for usage by autodoc
+from unittest import SkipTest
from util import TestApp, Struct, raises
-from nose.tools import with_setup
+from nose.tools import with_setup, eq_
from six import StringIO
from docutils.statemachine import ViewList
@@ -968,3 +969,46 @@ class InstAttCls(object):
self.ia2 = 'e'
"""Docstring for instance attribute InstAttCls.ia2."""
+
+
+def test_type_hints():
+ from sphinx.ext.autodoc import formatargspec
+ from sphinx.util.inspect import getargspec
+
+ try:
+ from typing_test_data import f0, f1, f2, f3, f4, f5, f6, f7, f8
+ except ImportError:
+ raise SkipTest
+
+ def verify_arg_spec(f, expected):
+ eq_(formatargspec(f, *getargspec(f)), expected)
+
+ # Class annotations
+ verify_arg_spec(f0, '(x: int, y: numbers.Integral) -> None')
+
+ # Generic types with concrete parameters
+ verify_arg_spec(f1, '(x: typing.List[int]) -> typing.List[int]')
+
+ # TypeVars and generic types with TypeVars
+ verify_arg_spec(f2, '(x: typing.List[T],'
+ ' y: typing.List[T_co],'
+ ' z: T) -> typing.List[T_contra]')
+
+ # Union types
+ verify_arg_spec(f3, '(x: typing.Union[str, numbers.Integral]) -> None')
+
+ # Quoted annotations
+ verify_arg_spec(f4, '(x: str, y: str) -> None')
+
+ # Keyword-only arguments
+ verify_arg_spec(f5, '(x: int, *, y: str, z: str) -> None')
+
+ # Space around '=' for defaults
+ verify_arg_spec(f6, '(x: int = None, y: dict = {}) -> None')
+
+ # Callable types
+ verify_arg_spec(f7, '(x: typing.Callable[[int, str], int]) -> None')
+
+ # Tuple types
+ verify_arg_spec(f8, '(x: typing.Tuple[int, str],'
+ ' y: typing.Tuple[int, ...]) -> None')