[Python-modules-commits] [sphinx] 02/04: Adapt to typing private API change in Python 3.5.2

Dmitry Shachnev mitya57 at moszumanska.debian.org
Tue May 17 13:09:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

mitya57 pushed a commit to branch master
in repository sphinx.

commit 5df9bd941bd36ecaf774490aca30e857d55168f0
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date:   Sun May 8 12:10:40 2016 +0300

    Adapt to typing private API change in Python 3.5.2
    
    Taken from: https://github.com/sphinx-doc/sphinx/pull/2532
    Fixes: https://github.com/sphinx-doc/sphinx/issues/2519
---
 sphinx/ext/autodoc.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index 7dc89d3..e32511a 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)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/sphinx.git



More information about the Python-modules-commits mailing list