diff --git a/CHANGES b/CHANGES index 3724c65cab3..d0e4e6316cc 100644 --- a/CHANGES +++ b/CHANGES @@ -37,6 +37,7 @@ Features added Bugs fixed ---------- +* #8074: napoleon: Crashes during processing C-ext module * #8084: autodoc: KeyError is raised on documenting an attribute of the broken class diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 52abf975339..29799cb06c3 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -1074,7 +1074,10 @@ def __init__(self, docstring: Union[str, List[str]], config: SphinxConfig = None super().__init__(docstring, config, app, what, name, obj, options) def _get_location(self) -> str: - filepath = inspect.getfile(self._obj) if self._obj is not None else None + try: + filepath = inspect.getfile(self._obj) if self._obj is not None else None + except TypeError: + filepath = None name = self._name if filepath is None and name is None: diff --git a/sphinx/registry.py b/sphinx/registry.py index 0aec0a9fd0c..4d1e9eb7246 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -367,7 +367,14 @@ def add_js_file(self, filename: str, **attributes: str) -> None: logger.debug('[app] adding js_file: %r, %r', filename, attributes) self.js_files.append((filename, attributes)) + def has_latex_package(self, name: str) -> bool: + packages = self.latex_packages + self.latex_packages_after_hyperref + return bool([x for x in packages if x[0] == name]) + def add_latex_package(self, name: str, options: str, after_hyperref: bool = False) -> None: + if self.has_latex_package(name): + logger.warn("latex package '%s' already included" % name) + logger.debug('[app] adding latex package: %r', name) if after_hyperref: self.latex_packages_after_hyperref.append((name, options)) diff --git a/sphinx/util/template.py b/sphinx/util/template.py index 18047d68758..bb078a2a246 100644 --- a/sphinx/util/template.py +++ b/sphinx/util/template.py @@ -84,6 +84,8 @@ def __init__(self, template_path: str = None, latex_engine: str = None) -> None: self.env.variable_end_string = '%>' self.env.block_start_string = '<%' self.env.block_end_string = '%>' + self.env.comment_start_string = '<#' + self.env.comment_end_string = '<#' class ReSTRenderer(SphinxRenderer):