From 0be08012cd8d9ba16d15ffa4d3540f56d3ac9dfc Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 21 Jun 2020 16:11:55 +0900 Subject: [PATCH] Fix #7856: autodoc: AttributeError is raised for non-class object --- CHANGES | 2 ++ sphinx/ext/autodoc/__init__.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index c1b97b58d..f85970ffe 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,8 @@ Bugs fixed ---------- * #7844: autodoc: Failed to detect module when relative module name given +* #7856: autodoc: AttributeError is raised when non-class object is given to + the autoclass directive Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 23245ad9c..bb89920be 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -826,7 +826,12 @@ class Documenter: self.add_line('', sourcename) # format the object's signature, if any - sig = self.format_signature() + try: + sig = self.format_signature() + except Exception as exc: + logger.warning(__('error while formatting signature for %s: %s'), + self.fullname, exc, type='autodoc') + return # generate the directive header and options, if applicable self.add_directive_header(sig)