summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc.py
diff options
context:
space:
mode:
authorJoost van Zwieten <joostvanzwieten@gmail.com>2016-07-29 12:27:00 +0200
committerJoost van Zwieten <joostvanzwieten@gmail.com>2016-08-07 16:18:22 +0200
commit099b58f7fee7d4688faebace615e781245bf20b8 (patch)
tree84863c6d1e33d0a666e6934d845bcee910774f46 /sphinx/ext/autodoc.py
parentda7e2d9dda35714111cdc98ba07b3a75d7d3886f (diff)
downloadsphinx-git-099b58f7fee7d4688faebace615e781245bf20b8.tar.gz
ext.autodoc: fix formatting instance annotations
Currently `format_annotation` fails on instances, because instances don't have `__module__` and `__qualname__` attributes. Defer building the `qualified_name` of an annotation until we have established that the annotation is a type.
Diffstat (limited to 'sphinx/ext/autodoc.py')
-rw-r--r--sphinx/ext/autodoc.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index 6ae0966fb..08bc99cdf 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -261,12 +261,13 @@ def format_annotation(annotation):
Displaying complex types from ``typing`` relies on its private API.
"""
+ if not isinstance(annotation, type):
+ return repr(annotation)
+
qualified_name = (annotation.__module__ + '.' + annotation.__qualname__
if annotation else repr(annotation))
- if not isinstance(annotation, type):
- return repr(annotation)
- elif annotation.__module__ == 'builtins':
+ if annotation.__module__ == 'builtins':
return annotation.__qualname__
elif typing:
if isinstance(annotation, typing.TypeVar):