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

This commit is contained in:
Takeshi KOMIYA
2016-11-13 00:01:41 +09:00
parent a2102d66ec
commit 4ca84aba45
6 changed files with 17 additions and 6 deletions
+1
View File
@@ -9,6 +9,7 @@ Bugs fixed
results in warning / error results in warning / error
* #3068: Allow the '=' character in the -D option of sphinx-build.py * #3068: Allow the '=' character in the -D option of sphinx-build.py
* #3074: ``add_source_parser()`` crashes in debug mode * #3074: ``add_source_parser()`` crashes in debug mode
* #3135: ``sphinx.ext.autodoc`` crashes with plain Callable
Release 1.4.8 (released Oct 1, 2016) Release 1.4.8 (released Oct 1, 2016)
==================================== ====================================
+3 -1
View File
@@ -306,7 +306,9 @@ def format_annotation(annotation):
hasattr(annotation, '__args__') and \ hasattr(annotation, '__args__') and \
hasattr(annotation, '__result__'): hasattr(annotation, '__result__'):
args = annotation.__args__ args = annotation.__args__
if args is Ellipsis: if args is None:
return qualified_name
elif args is Ellipsis:
args_str = '...' args_str = '...'
else: else:
formatted_args = (format_annotation(a) for a in args) formatted_args = (format_annotation(a) for a in args)
+1
View File
@@ -13,3 +13,4 @@ whoosh>=2.0
alabaster alabaster
sphinx_rtd_theme sphinx_rtd_theme
imagesize imagesize
typing
+4 -3
View File
@@ -1025,7 +1025,7 @@ def test_type_hints():
from sphinx.util.inspect import getargspec from sphinx.util.inspect import getargspec
try: 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): except (ImportError, SyntaxError):
raise SkipTest('Cannot import Python code with function annotations') raise SkipTest('Cannot import Python code with function annotations')
@@ -1057,10 +1057,11 @@ def test_type_hints():
# Callable types # Callable types
verify_arg_spec(f7, '(x: typing.Callable[[int, str], int]) -> None') verify_arg_spec(f7, '(x: typing.Callable[[int, str], int]) -> None')
verify_arg_spec(f8, '(x: typing.Callable) -> None')
# Tuple types # 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') ' y: typing.Tuple[int, ...]) -> None')
# Instance annotations # Instance annotations
verify_arg_spec(f9, '(x: CustomAnnotation, y: 123) -> None') verify_arg_spec(f10, '(x: CustomAnnotation, y: 123) -> None')
+7 -2
View File
@@ -44,7 +44,11 @@ def f7(x: Callable[[int, str], int]) -> None:
pass 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 pass
@@ -52,5 +56,6 @@ class CustomAnnotation:
def __repr__(self): def __repr__(self):
return 'CustomAnnotation' return 'CustomAnnotation'
def f9(x: CustomAnnotation(), y: 123) -> None:
def f10(x: CustomAnnotation(), y: 123) -> None:
pass pass
+1
View File
@@ -6,6 +6,7 @@ deps=
nose nose
sqlalchemy sqlalchemy
whoosh whoosh
typing
setenv = setenv =
SPHINX_TEST_TEMPDIR = {envdir}/testbuild SPHINX_TEST_TEMPDIR = {envdir}/testbuild
commands= commands=