You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importreimportinspectdefextract_params(docstring):
"""Extract :param lines from a docstring with their indentation."""ifnotdocstring:
return []
returnre.findall(r'(\s*:param [^:]+: [^\n]+)', docstring)
defmerge_docs(cls):
"""Decorator to merge :param lines from all parent classes."""parent_params=set()
forbaseininspect.getmro(cls)[1:]:
ifbase.__doc__:
parent_params.update(extract_params(base.__doc__))
ifcls.__doc__:
cls_params=set(extract_params(cls.__doc__))
else:
cls_params=set()
unique_params=parent_params-cls_params# Combine the class's original docstring with the new parameterscombined_doc=cls.__doc__or""ifcombined_docandunique_params:
combined_doc=combined_doc.rstrip() +"\n\n"combined_doc+="\n".join(unique_params)
cls.__doc__=combined_docreturncls@merge_docsclassOpenAI:
"""OpenAI base class. :param api_key: The API key for authentication. :param timeout: The timeout for API requests. """def__init__(self, api_key, timeout):
self.api_key=api_keyself.timeout=timeout@merge_docsclassOpenAIAudioTranslation(OpenAI):
"""OpenAI audio translation predictor. :param takes_context: Whether the model takes context into account. :param prompt: The prompt to guide the model's style. Should contain ``{context}``. """def__init__(self, api_key, timeout, takes_context, prompt):
super().__init__(api_key, timeout)
self.takes_context=takes_contextself.prompt=prompt# Print the updated __doc__ for the subclassprint(OpenAIAudioTranslation.__doc__)
blythed
changed the title
Handle super() doc-string parameters with public_api.
Handle super() doc-string parameters in a clever/ simple way.
May 14, 2024
We currently have custom formatting statements
__doc__ = __doc__.format(...)
. This should be handled in a simple way.The text was updated successfully, but these errors were encountered: