From: Vladimír Vondruš Date: Sat, 4 May 2019 19:27:12 +0000 (+0200) Subject: documentation/python: properly escape default values. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=4a5e8f69d29141e15bdb574d28c93beba124d1b5;p=blog.git documentation/python: properly escape default values. --- diff --git a/documentation/python.py b/documentation/python.py index 6b749314..032089d4 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -462,7 +462,7 @@ def extract_function_doc(state: State, parent, path: List[str], function) -> Lis # Don't include redundant type for the self argument if name == 'self': param.type = None else: param.type = type - param.default = default + param.default = html.escape(default or '') if type or default: out.has_complex_params = True # *args / **kwargs can still appear in the parsed signatures if diff --git a/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html b/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html index 4c104a0e..bbc62020 100644 --- a/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html +++ b/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html @@ -63,7 +63,7 @@
def instance_function_kwargs(self, hey: int, - what: str = 'eh?') -> Tuple[float, int] + what: str = '<eh?>') -> Tuple[float, int]
Instance method with position or keyword args
diff --git a/documentation/test_python/pybind_signatures/pybind_signatures.cpp b/documentation/test_python/pybind_signatures/pybind_signatures.cpp index ea145b27..40d055fb 100644 --- a/documentation/test_python/pybind_signatures/pybind_signatures.cpp +++ b/documentation/test_python/pybind_signatures/pybind_signatures.cpp @@ -52,7 +52,7 @@ PYBIND11_MODULE(pybind_signatures, m) { .def_static("static_function", &MyClass::staticFunction, "Static method with positional-only args") .def(py::init(), "Constructor") .def("instance_function", &MyClass::instanceFunction, "Instance method with positional-only args") - .def("instance_function_kwargs", &MyClass::instanceFunction, "Instance method with position or keyword args", py::arg("hey"), py::arg("what") = "eh?") + .def("instance_function_kwargs", &MyClass::instanceFunction, "Instance method with position or keyword args", py::arg("hey"), py::arg("what") = "") .def("another", &MyClass::another, "Instance method with no args, 'self' is thus position-only") .def_property("foo", &MyClass::foo, &MyClass::setFoo, "A read/write property"); }