From ac54bfc5761337aa606fb1aa6575745062ce26f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 24 Feb 2022 21:40:42 +0100 Subject: [PATCH] fix: Don't escape signatures return annotations Issue #6: https://github.com/mkdocstrings/python/issues/6 --- .../python/templates/material/_base/signature.html | 2 +- tests/test_renderer.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mkdocstrings_handlers/python/templates/material/_base/signature.html b/src/mkdocstrings_handlers/python/templates/material/_base/signature.html index 402e5d01..98658b6b 100644 --- a/src/mkdocstrings_handlers/python/templates/material/_base/signature.html +++ b/src/mkdocstrings_handlers/python/templates/material/_base/signature.html @@ -38,7 +38,7 @@ {%- endif -%} {%- endfor -%} ) - {%- if config.show_signature_annotations and function.annotation %} -> {{ function.annotation }}{%- endif -%} + {%- if config.show_signature_annotations and function.annotation %} -> {{ function.annotation|safe }}{%- endif -%} {%- endwith -%} {%- endif -%} \ No newline at end of file diff --git a/tests/test_renderer.py b/tests/test_renderer.py index 76f68b7c..31232e12 100644 --- a/tests/test_renderer.py +++ b/tests/test_renderer.py @@ -31,3 +31,15 @@ def test_render_docstring_examples_section(renderer): assert "

This is an example.

" in rendered assert "print" in rendered assert "Hello" in rendered + + +def test_format_code_and_signature(renderer): + """Assert code and signatures can be Black-formatted. + + Parameters: + renderer: A renderer instance (parametrized). + """ + assert renderer.do_format_code("print('Hello')", 100) + assert renderer.do_format_code('print("Hello")', 100) + assert renderer.do_format_signature("(param: str = 'hello') -> 'Class'", 100) + assert renderer.do_format_signature('(param: str = "hello") -> "Class"', 100)