From: Vladimír Vondruš Date: Thu, 7 May 2020 20:10:58 +0000 (+0200) Subject: documentation/python: deterministic formatting of function values. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=a1c50ef540817a780e25f43dc93948cf31ebc33d;p=blog.git documentation/python: deterministic formatting of function values. Otherwise it would be a different hash every time. --- 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.