From 5b84938cd2ec50a1da7d6d6eeb6157f9270705a8 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 18 Feb 2020 23:13:49 +0900 Subject: [PATCH] Fix #7178: autodoc: TypeError is raised on fetching type annotations --- CHANGES | 1 + sphinx/ext/autodoc/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index edd7f288dae..1abf17ff14d 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,7 @@ Bugs fixed * #7156: autodoc: separator for keyword only arguments is not shown * #7146: autodoc: IndexError is raised on suppressed type_comment found * #7161: autodoc: typehints extension does not support parallel build +* #7178: autodoc: TypeError is raised on fetching type annotations * #7151: crashed when extension assigns a value to ``env.indexentries`` * #7170: text: Remove debug print * #7137: viewcode: Avoid to crash when non-python code given diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index f433ea88aab..08e4e5301ee 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1236,7 +1236,7 @@ def add_directive_header(self, sig: str) -> None: if not self.options.annotation: # obtain annotation for this data annotations = getattr(self.parent, '__annotations__', {}) - if self.objpath[-1] in annotations: + if annotations and self.objpath[-1] in annotations: objrepr = stringify_typehint(annotations.get(self.objpath[-1])) self.add_line(' :type: ' + objrepr, sourcename) else: @@ -1424,7 +1424,7 @@ def add_directive_header(self, sig: str) -> None: if not self._datadescriptor: # obtain annotation for this attribute annotations = getattr(self.parent, '__annotations__', {}) - if self.objpath[-1] in annotations: + if annotations and self.objpath[-1] in annotations: objrepr = stringify_typehint(annotations.get(self.objpath[-1])) self.add_line(' :type: ' + objrepr, sourcename) else: