diff --git a/CHANGES b/CHANGES index f402b28b1..7b9e2b672 100644 --- a/CHANGES +++ b/CHANGES @@ -255,7 +255,10 @@ Bugs fixed ---------- * LaTeX: Remove extraneous space after author names on PDF title page (refs: #6004) +* #6026: LaTeX: A cross reference to definition list does not work * #6046: LaTeX: ``TypeError`` is raised when invalid latex_elements given +* #6019: imgconverter: Including multipage PDF fails +* #6047: autodoc: ``autofunction`` emits a warning for method objects Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index f76faf322..cd3b735e1 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1002,6 +1002,7 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ return None try: if (not isfunction(self.object) and + not inspect.ismethod(self.object) and not isbuiltin(self.object) and not inspect.isclass(self.object) and hasattr(self.object, '__call__')): diff --git a/sphinx/ext/imgconverter.py b/sphinx/ext/imgconverter.py index f4ba5d001..dd78883e2 100644 --- a/sphinx/ext/imgconverter.py +++ b/sphinx/ext/imgconverter.py @@ -54,9 +54,9 @@ class ImagemagickConverter(ImageConverter): # type: (str, str) -> bool """Converts the image to expected one.""" try: - if _from.lower().endswith('.gif'): - # when target is GIF format, pick the first frame - _from += '[0]' + # append an index 0 to source filename to pick up the first frame + # (or first page) of image (ex. Animation GIF, PDF) + _from += '[0]' args = ([self.config.image_converter] + self.config.image_converter_args + diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index 7870438f7..b0dd13b38 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -301,6 +301,15 @@ def traverse_parent(node, cls=None): node = node.parent +def get_prev_node(node): + # type: (nodes.Node) -> nodes.Node + pos = node.parent.index(node) + if pos > 0: + return node.parent[pos - 1] + else: + return None + + def traverse_translatable_index(doctree): # type: (nodes.Element) -> Iterable[Tuple[nodes.Element, List[str]]] """Traverse translatable index node from a document tree.""" diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index e2ca8989f..04731411f 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -28,9 +28,9 @@ from sphinx.deprecation import ( from sphinx.domains.std import StandardDomain from sphinx.errors import SphinxError from sphinx.locale import admonitionlabels, _, __ -from sphinx.util import split_into, logging + from sphinx.util import split_into, logging from sphinx.util.docutils import SphinxTranslator -from sphinx.util.nodes import clean_astext +from sphinx.util.nodes import clean_astext, get_prev_node from sphinx.util.template import LaTeXRenderer from sphinx.util.texescape import tex_escape_map, tex_replace_map @@ -1752,9 +1752,15 @@ class LaTeXTranslator(SphinxTranslator): elif domain.get_enumerable_node_type(next_node) and domain.get_numfig_title(next_node): return - if 'refuri' in node or 'refid' in node or 'refname' in node: - # skip indirect targets (external hyperlink and internal links) + if 'refuri' in node: return + if node.get('refid'): + prev_node = get_prev_node(node) + if isinstance(prev_node, nodes.reference) and node['refid'] == prev_node['refid']: + # a target for a hyperlink reference having alias + pass + else: + add_target(node['refid']) for id in node['ids']: add_target(id) diff --git a/tests/roots/test-ext-autodoc/target/callable.py b/tests/roots/test-ext-autodoc/target/callable.py index f3358eafd..6fcd5053e 100644 --- a/tests/roots/test-ext-autodoc/target/callable.py +++ b/tests/roots/test-ext-autodoc/target/callable.py @@ -4,5 +4,10 @@ class Callable(): def __call__(self, arg1, arg2, **kwargs): pass + def method(self, arg1, arg2): + """docstring of Callable.method().""" + pass + function = Callable() +method = function.method diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 943ba5a7a..42a1f4f3e 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -1365,6 +1365,19 @@ def test_autofunction_for_callable(app): ] +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_autofunction_for_method(app): + actual = do_autodoc(app, 'function', 'target.callable.method') + assert list(actual) == [ + '', + '.. py:function:: method(arg1, arg2)', + ' :module: target.callable', + '', + ' docstring of Callable.method().', + ' ' + ] + + @pytest.mark.sphinx('html', testroot='ext-autodoc') def test_mocked_module_imports(app, warning): # no autodoc_mock_imports