I am creating several classes dynamically and I want them to have different docstrings. I have:
def make_class(class_docstring): class X: pass X.__doc__ = class_docstring return X
This did not work because docstrings are read-only. Then I tried:
def make_class(class_name, class_docstring): class X: def __init__(self): super().__init__() d = {'__doc__': class_docstring} d.update(X.__dict__) return type(class_name, (), d) ClassName = make_class( 'ClassName', """ Some docstring... """)
which worked until he had to call super .
What is the correct way to dynamically set the docstring attribute?
source share