diff options
author | Dmitry Shachnev <mitya57@gmail.com> | 2016-05-08 12:10:40 +0300 |
---|---|---|
committer | Dmitry Shachnev <mitya57@gmail.com> | 2016-05-08 12:24:44 +0300 |
commit | 696237c50e5c3175023ece434fb69cf28107413c (patch) | |
tree | da34e8ecb340993e39347201fbb3571d43be24f3 | |
parent | 287e46d30c61b7587a6ba0c3d524e5d56105a898 (diff) | |
download | sphinx-git-696237c50e5c3175023ece434fb69cf28107413c.tar.gz |
Adapt to typing private API change in Python 3.5.2
Fixes #2519.
-rw-r--r-- | sphinx/ext/autodoc.py | 14 |
1 files changed, 11 insertions, 3 deletions
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) |