Skip to content

Commit

Permalink
Fix sphinx-doc#8085: autodoc: AttributeError is raised on documenting…
Browse files Browse the repository at this point in the history
… an attribute

Until Python 3.5.2, typing.get_type_hints() raises AttributeError if
given object does not have `__code__` attribute.  This handles the
exception not to crash building documents.

refs: python/cpython@991d14f
  • Loading branch information
tk0miya committed Aug 10, 2020
1 parent bf26080 commit c74c422
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -40,6 +40,8 @@ Bugs fixed
* #8074: napoleon: Crashes during processing C-ext module
* #8084: autodoc: KeyError is raised on documenting an attribute of the broken
class
* #8085: autodoc: AttributeError is raised on documenting an attribute on Python
3.5.2

Testing
--------
Expand Down
6 changes: 6 additions & 0 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -1613,6 +1613,9 @@ def add_directive_header(self, sig: str) -> None:
except KeyError:
# a broken class found (refs: https://github.com/sphinx-doc/sphinx/issues/8084)
annotations = {}
except AttributeError:
# AttributeError is raised on 3.5.2 (fixed by 3.5.3)
annotations = {}

if self.objpath[-1] in annotations:
objrepr = stringify_typehint(annotations.get(self.objpath[-1]))
Expand Down Expand Up @@ -1986,6 +1989,9 @@ def add_directive_header(self, sig: str) -> None:
except KeyError:
# a broken class found (refs: https://github.com/sphinx-doc/sphinx/issues/8084)
annotations = {}
except AttributeError:
# AttributeError is raised on 3.5.2 (fixed by 3.5.3)
annotations = {}

if self.objpath[-1] in annotations:
objrepr = stringify_typehint(annotations.get(self.objpath[-1]))
Expand Down

0 comments on commit c74c422

Please sign in to comment.