From 696237c50e5c3175023ece434fb69cf28107413c Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sun, 8 May 2016 12:10:40 +0300 Subject: Adapt to typing private API change in Python 3.5.2 Fixes #2519. --- sphinx/ext/autodoc.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'sphinx/ext/autodoc.py') diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 7dc89d39a..e32511afa 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -269,9 +269,17 @@ def format_annotation(annotation): if isinstance(annotation, typing.TypeVar): return annotation.__name__ elif hasattr(typing, 'GenericMeta') and \ - isinstance(annotation, typing.GenericMeta) and \ - hasattr(annotation, '__parameters__'): - params = annotation.__parameters__ + isinstance(annotation, typing.GenericMeta): + # In Python 3.5.2+, all arguments are stored in __args__, + # whereas __parameters__ only contains generic parameters. + # + # Prior to Python 3.5.2, __args__ is not available, and all + # arguments are in __parameters__. + params = None + if hasattr(annotation, '__args__'): + params = annotation.__args__ + elif hasattr(annotation, '__parameters__'): + params = annotation.__parameters__ if params is not None: param_str = ', '.join(format_annotation(p) for p in params) return '%s[%s]' % (qualified_name, param_str) -- cgit v1.2.1