diff options
Diffstat (limited to 'doc/tools/make_rst.py')
-rwxr-xr-x | doc/tools/make_rst.py | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/doc/tools/make_rst.py b/doc/tools/make_rst.py index 761a7f8f4a..101660881b 100755 --- a/doc/tools/make_rst.py +++ b/doc/tools/make_rst.py @@ -1311,9 +1311,6 @@ def make_rst_class(class_def: ClassDef, state: State, dry_run: bool, output_dir: if property_def.text is not None and property_def.text.strip() != "": f.write(f"{format_text_block(property_def.text.strip(), property_def, state)}\n\n") - if property_def.type_name.type_name in PACKED_ARRAY_TYPES: - tmp = f"[b]Note:[/b] The returned array is [i]copied[/i] and any changes to it will not update the original property value. See [{property_def.type_name.type_name}] for more details." - f.write(f"{format_text_block(tmp, property_def, state)}\n\n") elif property_def.deprecated is None and property_def.experimental is None: f.write(".. container:: contribute\n\n\t") f.write( @@ -1323,6 +1320,11 @@ def make_rst_class(class_def: ClassDef, state: State, dry_run: bool, output_dir: + "\n\n" ) + # Add copy note to built-in properties returning `Packed*Array`. + if property_def.type_name.type_name in PACKED_ARRAY_TYPES: + copy_note = f"[b]Note:[/b] The returned array is [i]copied[/i] and any changes to it will not update the original property value. See [{property_def.type_name.type_name}] for more details." + f.write(f"{format_text_block(copy_note, property_def, state)}\n\n") + index += 1 # Constructor, Method, Operator descriptions @@ -1507,24 +1509,23 @@ def make_type(klass: str, state: State) -> str: if klass.find("*") != -1: # Pointer, ignore return f"``{klass}``" - link_type = klass - is_array = False + def resolve_type(link_type: str) -> str: + if link_type in state.classes: + return f":ref:`{link_type}<class_{link_type}>`" + else: + print_error(f'{state.current_class}.xml: Unresolved type "{link_type}".', state) + return f"``{link_type}``" - if link_type.endswith("[]"): # Typed array, strip [] to link to contained type. - link_type = link_type[:-2] - is_array = True + if klass.endswith("[]"): # Typed array, strip [] to link to contained type. + return f":ref:`Array<class_Array>`\\[{resolve_type(klass[:-len('[]')])}\\]" - if link_type in state.classes: - type_rst = f":ref:`{link_type}<class_{link_type}>`" - if is_array: - type_rst = f":ref:`Array<class_Array>`\\[{type_rst}\\]" - return type_rst + if klass.startswith("Dictionary["): # Typed dictionary, split elements to link contained types. + parts = klass[len("Dictionary[") : -len("]")].partition(", ") + key = parts[0] + value = parts[2] + return f":ref:`Dictionary<class_Dictionary>`\\[{resolve_type(key)}, {resolve_type(value)}\\]" - print_error(f'{state.current_class}.xml: Unresolved type "{link_type}".', state) - type_rst = f"``{link_type}``" - if is_array: - type_rst = f":ref:`Array<class_Array>`\\[{type_rst}\\]" - return type_rst + return resolve_type(klass) def make_enum(t: str, is_bitfield: bool, state: State) -> str: |