Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-31 12:35:40 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-31 12:41:19 +0300
commite6f445f2f8fd5f2fbb85e330b36da561f43b61b7 (patch)
treefe66f6341e5e45b264aaa9a54cbf88e9443cc828 /sphinx/ext
parentbe20f178924fbb610f69cd30ef25a78aa1a892df (diff)
refactor: AttributeError handling for getmro() is not needed
Internally, sphinx.util.inspect.getmro() uses `safe_getattr()` with the `default` keyword. Therefore it never raises AttributeError even if the subject raises an error on accessing `__mro__` attribute. This fixes the wrong its usage.
Diffstat (limited to 'sphinx/ext')
-rw-r--r--sphinx/ext/autodoc/__init__.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index 1490d1551..797b80dea 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -2505,22 +2505,19 @@ class AttributeDocumenter(GenericAliasMixin, NewTypeMixin, SlotsMixin, # type:
pass
def get_attribute_comment(self, parent: Any, attrname: str) -> Optional[List[str]]:
- try:
- for cls in inspect.getmro(parent):
- try:
- module = safe_getattr(cls, '__module__')
- qualname = safe_getattr(cls, '__qualname__')
-
- analyzer = ModuleAnalyzer.for_module(module)
- analyzer.analyze()
- if qualname and self.objpath:
- key = (qualname, attrname)
- if key in analyzer.attr_docs:
- return list(analyzer.attr_docs[key])
- except (AttributeError, PycodeError):
- pass
- except (AttributeError, PycodeError):
- pass
+ for cls in inspect.getmro(parent):
+ try:
+ module = safe_getattr(cls, '__module__')
+ qualname = safe_getattr(cls, '__qualname__')
+
+ analyzer = ModuleAnalyzer.for_module(module)
+ analyzer.analyze()
+ if qualname and self.objpath:
+ key = (qualname, attrname)
+ if key in analyzer.attr_docs:
+ return list(analyzer.attr_docs[key])
+ except (AttributeError, PycodeError):
+ pass
return None