From 643131a98b100d3c97e1c0a23c9a35bcee5fdd91 Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Thu, 13 May 2021 19:53:00 +0200 Subject: [PATCH 1/7] Add HTML markup to the return type hint. --- sphinx/writers/html5.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 4696425910b..16cdccc163e 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -145,10 +145,10 @@ def depart_desc_type(self, node: Element) -> None: pass def visit_desc_returns(self, node: Element) -> None: - self.body.append(' → ') + self.body.append(' ') def depart_desc_returns(self, node: Element) -> None: - pass + self.body.append('') def visit_desc_parameterlist(self, node: Element) -> None: self.body.append('(') From cf2d5b3f32fbb92483ca815cd5fea4d04018645b Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Sat, 15 May 2021 15:32:18 +0200 Subject: [PATCH 2/7] Rename CSS classes for return type hint HTML markup. Wrap the complete type hint in a additional to enable showing the typehint as a popup on hover. Port changes to sphinx/writers/html.py. --- sphinx/writers/html.py | 4 ++-- sphinx/writers/html5.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index d633f07e8e0..e670c402bda 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -174,10 +174,10 @@ def depart_desc_type(self, node: Element) -> None: pass def visit_desc_returns(self, node: Element) -> None: - self.body.append(' → ') + self.body.append(' ') def depart_desc_returns(self, node: Element) -> None: - pass + self.body.append('') def visit_desc_parameterlist(self, node: Element) -> None: self.body.append('(') diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 16cdccc163e..5db75764236 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -145,10 +145,10 @@ def depart_desc_type(self, node: Element) -> None: pass def visit_desc_returns(self, node: Element) -> None: - self.body.append(' ') + self.body.append(' ') def depart_desc_returns(self, node: Element) -> None: - self.body.append('') + self.body.append('') def visit_desc_parameterlist(self, node: Element) -> None: self.body.append('(') From b079543405498630648fae40337b2b5a81ceed78 Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Sun, 16 May 2021 12:13:17 +0200 Subject: [PATCH 3/7] Add configuration option html_signaturereturn_icon for the arrow before a return type hint. --- doc/usage/configuration.rst | 5 +++++ sphinx/builders/html/__init__.py | 1 + sphinx/writers/html.py | 4 +++- sphinx/writers/html5.py | 4 +++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 0b2bd4e3eab..9993e5078d2 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1191,6 +1191,11 @@ that use Sphinx's HTMLWriter class. .. versionadded:: 3.5 +.. confval:: html_signaturereturn_icon + + A text for prepended to the type hint for the return type of a function or + method. HTML tags are allowed. Default: an wrrow; ``→`` + .. confval:: html_sidebars Custom sidebar templates, must be a dictionary that maps document names to diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 85669474eab..34103ad98e3 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -1320,6 +1320,7 @@ def setup(app: Sphinx) -> Dict[str, Any]: app.add_config_value('html_add_permalinks', UNSET, 'html') app.add_config_value('html_permalinks', True, 'html') app.add_config_value('html_permalinks_icon', '¶', 'html') + app.add_config_value('html_signaturereturn_icon', '→', 'html') app.add_config_value('html_use_index', True, 'html') app.add_config_value('html_split_index', False, 'html') app.add_config_value('html_copy_source', True, 'html') diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index e670c402bda..9fd9fe71526 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -174,7 +174,9 @@ def depart_desc_type(self, node: Element) -> None: pass def visit_desc_returns(self, node: Element) -> None: - self.body.append(' ') + self.body.append(' ') + self.body.append(self.config.html_signaturereturn_icon) + self.body.append(' ') def depart_desc_returns(self, node: Element) -> None: self.body.append('') diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 5db75764236..1df9bb46698 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -145,7 +145,9 @@ def depart_desc_type(self, node: Element) -> None: pass def visit_desc_returns(self, node: Element) -> None: - self.body.append(' ') + self.body.append(' ') + self.body.append(self.config.html_signaturereturn_icon) + self.body.append(' ') def depart_desc_returns(self, node: Element) -> None: self.body.append('') From 6af23a9d7a6421754916fea68961d6e6bdc28677 Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Sat, 22 May 2021 17:11:20 +0200 Subject: [PATCH 4/7] Fix typo. --- doc/usage/configuration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 9993e5078d2..3d59d2e8991 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1194,7 +1194,7 @@ that use Sphinx's HTMLWriter class. .. confval:: html_signaturereturn_icon A text for prepended to the type hint for the return type of a function or - method. HTML tags are allowed. Default: an wrrow; ``→`` + method. HTML tags are allowed. Default: an arrow; ``→`` .. confval:: html_sidebars From ac2eb0397a9dd6cbb03bc613f8b1ff3023dfee41 Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Sat, 22 May 2021 18:09:13 +0200 Subject: [PATCH 5/7] Add version info for html_signaturereturn_icon. --- doc/usage/configuration.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 3d59d2e8991..6a3b19da465 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1196,6 +1196,8 @@ that use Sphinx's HTMLWriter class. A text for prepended to the type hint for the return type of a function or method. HTML tags are allowed. Default: an arrow; ``→`` + .. versionadded:: 4.1 + .. confval:: html_sidebars Custom sidebar templates, must be a dictionary that maps document names to From 798adc4f57ef0fd3b79e90ef6176c1f554b4e53b Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Sat, 22 May 2021 20:15:11 +0200 Subject: [PATCH 6/7] Add tests for html_signaturereturn_icon. --- .../test-html_signaturereturn_icon/conf.py | 1 + .../test-html_signaturereturn_icon/index.rst | 4 ++++ tests/test_build_html.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/roots/test-html_signaturereturn_icon/conf.py create mode 100644 tests/roots/test-html_signaturereturn_icon/index.rst diff --git a/tests/roots/test-html_signaturereturn_icon/conf.py b/tests/roots/test-html_signaturereturn_icon/conf.py new file mode 100644 index 00000000000..a695d180491 --- /dev/null +++ b/tests/roots/test-html_signaturereturn_icon/conf.py @@ -0,0 +1 @@ +extensions = ['sphinx.ext.autodoc'] diff --git a/tests/roots/test-html_signaturereturn_icon/index.rst b/tests/roots/test-html_signaturereturn_icon/index.rst new file mode 100644 index 00000000000..4ff4eb62bb6 --- /dev/null +++ b/tests/roots/test-html_signaturereturn_icon/index.rst @@ -0,0 +1,4 @@ +test-html_signaturereturn_icon +============================== + +.. py:function:: foo(a: bool, b: int) -> str diff --git a/tests/test_build_html.py b/tests/test_build_html.py index c74552d9e83..3e2c2e4d40d 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -1625,3 +1625,20 @@ def test_html_permalink_icon(app): assert ('

The basic Sphinx documentation for testing[PERMALINK]

' in content) + + +@pytest.mark.sphinx('html', testroot='html_signaturereturn_icon') +def test_html_signaturereturn_icon_default(app): + app.build() + content = (app.outdir / 'index.html').read_text() + + assert ('' in content) + + +@pytest.mark.sphinx('html', testroot='html_signaturereturn_icon', + confoverrides={'html_signaturereturn_icon': 'RETURN'}) +def test_html_signaturereturn_icon_custon(app): + app.build() + content = (app.outdir / 'index.html').read_text() + + assert ('RETURN' in content) From 9aedeee53891bcbbba0b0adaf72a3e30f99a00f7 Mon Sep 17 00:00:00 2001 From: Walter Doerwald Date: Mon, 14 Jun 2021 14:02:19 +0200 Subject: [PATCH 7/7] Remove configuration option html_signaturereturn_icon. --- doc/usage/configuration.rst | 7 ------- sphinx/builders/html/__init__.py | 1 - sphinx/writers/html.py | 6 +++--- sphinx/writers/html5.py | 6 +++--- tests/test_build_html.py | 11 +---------- 5 files changed, 7 insertions(+), 24 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 6a3b19da465..0b2bd4e3eab 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1191,13 +1191,6 @@ that use Sphinx's HTMLWriter class. .. versionadded:: 3.5 -.. confval:: html_signaturereturn_icon - - A text for prepended to the type hint for the return type of a function or - method. HTML tags are allowed. Default: an arrow; ``→`` - - .. versionadded:: 4.1 - .. confval:: html_sidebars Custom sidebar templates, must be a dictionary that maps document names to diff --git a/sphinx/builders/html/__init__.py b/sphinx/builders/html/__init__.py index 34103ad98e3..85669474eab 100644 --- a/sphinx/builders/html/__init__.py +++ b/sphinx/builders/html/__init__.py @@ -1320,7 +1320,6 @@ def setup(app: Sphinx) -> Dict[str, Any]: app.add_config_value('html_add_permalinks', UNSET, 'html') app.add_config_value('html_permalinks', True, 'html') app.add_config_value('html_permalinks_icon', '¶', 'html') - app.add_config_value('html_signaturereturn_icon', '→', 'html') app.add_config_value('html_use_index', True, 'html') app.add_config_value('html_split_index', False, 'html') app.add_config_value('html_copy_source', True, 'html') diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 9fd9fe71526..ce01326258d 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -174,9 +174,9 @@ def depart_desc_type(self, node: Element) -> None: pass def visit_desc_returns(self, node: Element) -> None: - self.body.append(' ') - self.body.append(self.config.html_signaturereturn_icon) - self.body.append(' ') + self.body.append(' ') + self.body.append('') + self.body.append(' ') def depart_desc_returns(self, node: Element) -> None: self.body.append('') diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 1df9bb46698..95dc920529d 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -145,9 +145,9 @@ def depart_desc_type(self, node: Element) -> None: pass def visit_desc_returns(self, node: Element) -> None: - self.body.append(' ') - self.body.append(self.config.html_signaturereturn_icon) - self.body.append(' ') + self.body.append(' ') + self.body.append('') + self.body.append(' ') def depart_desc_returns(self, node: Element) -> None: self.body.append('') diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 3e2c2e4d40d..958dee56833 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -1628,17 +1628,8 @@ def test_html_permalink_icon(app): @pytest.mark.sphinx('html', testroot='html_signaturereturn_icon') -def test_html_signaturereturn_icon_default(app): +def test_html_signaturereturn_icon(app): app.build() content = (app.outdir / 'index.html').read_text() assert ('' in content) - - -@pytest.mark.sphinx('html', testroot='html_signaturereturn_icon', - confoverrides={'html_signaturereturn_icon': 'RETURN'}) -def test_html_signaturereturn_icon_custon(app): - app.build() - content = (app.outdir / 'index.html').read_text() - - assert ('RETURN' in content)