Wrapper that automatically generates docstring.
(
func,
parent_class=None,
custom_intro=None,
custom_args=None,
checkpoint=None,
source_args_dict=None,
allowed_params=None,
)
| 4098 | |
| 4099 | |
| 4100 | def auto_method_docstring( |
| 4101 | func, |
| 4102 | parent_class=None, |
| 4103 | custom_intro=None, |
| 4104 | custom_args=None, |
| 4105 | checkpoint=None, |
| 4106 | source_args_dict=None, |
| 4107 | allowed_params=None, |
| 4108 | ): |
| 4109 | """ |
| 4110 | Wrapper that automatically generates docstring. |
| 4111 | """ |
| 4112 | |
| 4113 | # Use inspect to retrieve the method's signature |
| 4114 | sig = inspect.signature(func) |
| 4115 | indent_level = get_indent_level(func) if not parent_class else get_indent_level(parent_class) |
| 4116 | |
| 4117 | # Get model information |
| 4118 | model_name_lowercase, class_name, config_class = _get_model_info(func, parent_class) |
| 4119 | func_documentation = func.__doc__ |
| 4120 | |
| 4121 | if custom_args is not None and func_documentation is not None: |
| 4122 | func_documentation = "\n" + set_min_indent(custom_args.strip("\n"), 0) + "\n" + func_documentation |
| 4123 | elif custom_args is not None: |
| 4124 | func_documentation = "\n" + set_min_indent(custom_args.strip("\n"), 0) |
| 4125 | |
| 4126 | # Add intro to the docstring before args description if needed |
| 4127 | if custom_intro is not None: |
| 4128 | docstring = set_min_indent(custom_intro, indent_level + 4) |
| 4129 | if not docstring.strip().endswith("\n"): |
| 4130 | docstring += "\n" |
| 4131 | else: |
| 4132 | docstring = add_intro_docstring(func, class_name=class_name, indent_level=indent_level) |
| 4133 | |
| 4134 | # Process Parameters section |
| 4135 | docstring += _process_parameters_section( |
| 4136 | func_documentation, |
| 4137 | sig, |
| 4138 | func, |
| 4139 | class_name, |
| 4140 | model_name_lowercase, |
| 4141 | parent_class, |
| 4142 | indent_level, |
| 4143 | source_args_dict, |
| 4144 | allowed_params, |
| 4145 | ) |
| 4146 | |
| 4147 | # Process Returns section |
| 4148 | return_docstring, func_documentation = _process_returns_section( |
| 4149 | func_documentation, sig, config_class, indent_level |
| 4150 | ) |
| 4151 | docstring += return_docstring |
| 4152 | |
| 4153 | # Process Example section |
| 4154 | example_docstring = _process_example_section( |
| 4155 | func_documentation, |
| 4156 | func, |
| 4157 | parent_class, |
no test coverage detected