Skip to content

Commit

Permalink
Fix sphinx-doc#8200: autodoc: type aliases break type formatting
Browse files Browse the repository at this point in the history
The annotation option is shared between auto directives unexpectedly.
It causes supression of type annotations for objects after
GenericAlias definition.
  • Loading branch information
tk0miya committed Sep 12, 2020
1 parent a16cca2 commit df3bd91
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -19,6 +19,7 @@ Bugs fixed
* #8085: i18n: Add support for having single text domain
* #8143: autodoc: AttributeError is raised when False value is passed to
autodoc_default_options
* #8200: autodoc: type aliases break type formatting of autoattribute
* #8093: The highlight warning has wrong location in some builders (LaTeX,
singlehtml and so on)

Expand Down
6 changes: 4 additions & 2 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -1707,7 +1707,8 @@ def can_document_member(cls, member: Any, membername: str, isattr: bool, parent:
return inspect.isgenericalias(member)

def add_directive_header(self, sig: str) -> None:
self.options.annotation = SUPPRESS # type: ignore
self.options = Options(self.options)
self.options['annotation'] = SUPPRESS
super().add_directive_header(sig)

def add_content(self, more_content: Any, no_docstring: bool = False) -> None:
Expand All @@ -1731,7 +1732,8 @@ def can_document_member(cls, member: Any, membername: str, isattr: bool, parent:
return isinstance(member, TypeVar) and isattr # type: ignore

def add_directive_header(self, sig: str) -> None:
self.options.annotation = SUPPRESS # type: ignore
self.options = Options(self.options)
self.options['annotation'] = SUPPRESS
super().add_directive_header(sig)

def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]:
Expand Down

0 comments on commit df3bd91

Please sign in to comment.