From eceb20e14105bb1abdc72850c5679a017c06e960 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 27 Sep 2024 15:33:56 +0200 Subject: [PATCH] documentation/python: no reason to have the same code in two branches. Also it could be a plain join(), without having to parse the format template. --- documentation/python.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/documentation/python.py b/documentation/python.py index 775f5e5f..2e3988ce 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -1088,13 +1088,11 @@ def parse_pybind_docstring(state: State, referrer_path: List[str], doc: str) -> def format_value(state: State, referrer_path: List[str], value) -> Optional[Tuple[str, str, str]]: if value is None: return str(value), str(value), str(value) - if isinstance(value, enum.Enum): + # pybind enums don't inherit from enum.Enum but have the __members__ + # attribute instead + if isinstance(value, enum.Enum) or (state.config['PYBIND11_COMPATIBILITY'] and hasattr(value.__class__, '__members__')): # TODO Python 3.8+ supports `a, *b`, switch to that once 3.7 is dropped - return (value.name, ) + make_name_relative_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, value.name)) - # pybind enums have the __members__ attribute instead - elif state.config['PYBIND11_COMPATIBILITY'] and hasattr(value.__class__, '__members__'): - # TODO Python 3.8+ supports `a, *b`, switch to that once 3.7 is dropped - return (value.name, ) + make_name_relative_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, value.name)) + return (value.name, ) + make_name_relative_link(state, referrer_path, '.'.join([value.__class__.__module__, value.__class__.__qualname__, value.name])) # isbuiltin returns true if object is a builtin _function_ or _method_, not # just any builtin such as the False literal elif inspect.isfunction(value) or inspect.isbuiltin(value): -- 2.30.2