diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-11-02 20:06:30 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-11-02 20:08:21 +0900 |
commit | b014c34586beeeeb9522769b4d7deea8ac5ba75d (patch) | |
tree | fe8aedabf2b288baa38f2827b4192369111d8bcd /sphinx/ext/autodoc.py | |
parent | da1e157e90e58b62d24a708c1813a7279d854b42 (diff) | |
download | sphinx-git-b014c34586beeeeb9522769b4d7deea8ac5ba75d.tar.gz |
Fix #3111: autodoc crashes with python3.6b3
Since 3.6b3, structure of typing.Callable has been changed.
Diffstat (limited to 'sphinx/ext/autodoc.py')
-rw-r--r-- | sphinx/ext/autodoc.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 890f65646..98783cfdb 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -270,6 +270,8 @@ def format_annotation(annotation): """ if typing and isinstance(annotation, typing.TypeVar): return annotation.__name__ + if annotation == Ellipsis: + return '...' if not isinstance(annotation, type): return repr(annotation) @@ -288,7 +290,12 @@ def format_annotation(annotation): # arguments are in __parameters__. params = None if hasattr(annotation, '__args__'): - params = annotation.__args__ + if len(annotation.__args__) <= 2: + params = annotation.__args__ + else: # typing.Callable + args = ', '.join(format_annotation(a) for a in annotation.__args__[:-1]) + result = format_annotation(annotation.__args__[-1]) + return '%s[[%s], %s]' % (qualified_name, args, result) elif hasattr(annotation, '__parameters__'): params = annotation.__parameters__ if params is not None: |