From a1c50ef540817a780e25f43dc93948cf31ebc33d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 7 May 2020 22:10:58 +0200 Subject: [PATCH] documentation/python: deterministic formatting of function values. Otherwise it would be a different hash every time. --- documentation/python.py | 4 +++- .../inspect_value_formatting/inspect_value_formatting.html | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/documentation/python.py b/documentation/python.py index 8f32c501..933a4106 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -915,7 +915,7 @@ def parse_pybind_docstring(state: State, referrer_path: List[str], doc: str) -> # Used to format function default arguments and data values. *Not* pybind's # function default arguments, as those are parsed from a string representation. -def format_value(state: State, referrer_path: List[str], value: str) -> Optional[str]: +def format_value(state: State, referrer_path: List[str], value) -> Optional[str]: if value is None: return str(value) if isinstance(value, enum.Enum): return make_name_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, value.name)) @@ -924,6 +924,8 @@ def format_value(state: State, referrer_path: List[str], value: str) -> Optional # out of a str() instead. elif state.config['PYBIND11_COMPATIBILITY'] and hasattr(value.__class__, '__members__'): return make_name_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, str(value).partition('.')[2])) + elif inspect.isfunction(value): + return html.escape(''.format(value.__name__)) elif '__repr__' in type(value).__dict__: rendered = repr(value) # TODO: tuples of non-representable values will still be ugly diff --git a/documentation/test_python/inspect_value_formatting/inspect_value_formatting.html b/documentation/test_python/inspect_value_formatting/inspect_value_formatting.html index f89eac7e..be5bb673 100644 --- a/documentation/test_python/inspect_value_formatting/inspect_value_formatting.html +++ b/documentation/test_python/inspect_value_formatting/inspect_value_formatting.html @@ -55,7 +55,7 @@
- def setup_callback(callback = <function basics at 0x7fc2ca424ee0>) + def setup_callback(callback = <function basics>)
Should produce a deterministic output.
-- 2.30.2