distilabel icon indicating copy to clipboard operation
distilabel copied to clipboard

[FEATURE] Create decorator to include the docstrings of the parent class

Open plaguss opened this issue 9 months ago • 0 comments

Is your feature request related to a problem? Please describe. The LLM classes could use the docstrings from the parent class, see for example AnyscaleLLM.

Describe the solution you'd like

Using a decorator like:

@add_parent_docstrings()
class AnyscaleLLM(OpenAILLM):
    ...

The decorator should take into account that when parsed using parse_google_docstring, it should include the attributes not found in the current class (the child class takes precedence).

Initial draft:

def add_parent_docstrings(extra_docstrings: Optional[str] = None):
    def docstring_decorator(cls):
        parent_cls_docs = cls.__bases__[0].__doc__
        if extra_docstrings:
            parent_cls_docs += f"\n{extra_docstrings}"
        cls.__doc__ += f"\n{parent_cls_docs}"
        return cls
    return docstring_decorator

Describe alternatives you've considered Whatever easier way to render nicely the docs from the parent class when required.

Additional context Add any other context or screenshots about the feature request here.

plaguss avatar May 17 '24 11:05 plaguss