Fix #3135: `sphinx.ext.autodoc` crashes with plain Callable

This commit is contained in:
Takeshi KOMIYA
2016-11-12 23:57:29 +09:00
parent a2102d66ec
commit 4ca84aba45
6 changed files with 17 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ Bugs fixed
results in warning / error
* #3068: Allow the '=' character in the -D option of sphinx-build.py
* #3074: ``add_source_parser()`` crashes in debug mode
* #3135: ``sphinx.ext.autodoc`` crashes with plain Callable
Release 1.4.8 (released Oct 1, 2016)
====================================

View File

@@ -306,7 +306,9 @@ def format_annotation(annotation):
hasattr(annotation, '__args__') and \
hasattr(annotation, '__result__'):
args = annotation.__args__
if args is Ellipsis:
if args is None:
return qualified_name
elif args is Ellipsis:
args_str = '...'
else:
formatted_args = (format_annotation(a) for a in args)

View File

@@ -13,3 +13,4 @@ whoosh>=2.0
alabaster
sphinx_rtd_theme
imagesize
typing

View File

@@ -1025,7 +1025,7 @@ def test_type_hints():
from sphinx.util.inspect import getargspec
try:
from typing_test_data import f0, f1, f2, f3, f4, f5, f6, f7, f8, f9
from typing_test_data import f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10
except (ImportError, SyntaxError):
raise SkipTest('Cannot import Python code with function annotations')
@@ -1057,10 +1057,11 @@ def test_type_hints():
# Callable types
verify_arg_spec(f7, '(x: typing.Callable[[int, str], int]) -> None')
verify_arg_spec(f8, '(x: typing.Callable) -> None')
# Tuple types
verify_arg_spec(f8, '(x: typing.Tuple[int, str],'
verify_arg_spec(f9, '(x: typing.Tuple[int, str],'
' y: typing.Tuple[int, ...]) -> None')
# Instance annotations
verify_arg_spec(f9, '(x: CustomAnnotation, y: 123) -> None')
verify_arg_spec(f10, '(x: CustomAnnotation, y: 123) -> None')

View File

@@ -44,7 +44,11 @@ def f7(x: Callable[[int, str], int]) -> None:
pass
def f8(x: Tuple[int, str], y: Tuple[int, ...]) -> None:
def f8(x: Callable) -> None:
pass
def f9(x: Tuple[int, str], y: Tuple[int, ...]) -> None:
pass
@@ -52,5 +56,6 @@ class CustomAnnotation:
def __repr__(self):
return 'CustomAnnotation'
def f9(x: CustomAnnotation(), y: 123) -> None:
def f10(x: CustomAnnotation(), y: 123) -> None:
pass

View File

@@ -6,6 +6,7 @@ deps=
nose
sqlalchemy
whoosh
typing
setenv =
SPHINX_TEST_TEMPDIR = {envdir}/testbuild
commands=