I am dynamically creating some classes and I want them to have different docstrings. I have:
def make_class(class_docstring):
class X:
pass
X.__doc__ = class_docstring
return X
That didn't 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 it had to call super.
What is the correct way to dynamically set the docstring attribute?