<div dir="ltr"><div><div><div><div>Recently I helped out on issue16954 which involved filling in docstrings </div><div>for methods and classes in ElementTree.py</div><div><br></div><div>While doing so, I tried to test my work in the interpreter like this...</div>
<div><br></div><div>    >>> from xml.etree.ElementTree import Element</div><div>    >>> help(Element)</div><div><br></div><div>...but found that help() showed nothing but empty strings!</div><div><br></div>
<div>After some debugging, I found that the culprit was the</div><div> `from _elementtree import *` near the bottom of the module.</div><div><br></div><div>Not wanting to copy & paste docstrings around,  I thought one solution </div>
<div>might be to just reassign Element.__doc__ with the right docstring. </div><div>But, it seems that you can't do that for C extensions:</div><div><br></div><div>    >>> from _elementtree import Element as cElement</div>
<div>    >>> cElement.__doc__ = 'correct docstring'</div><div>    Traceback (most recent call last):</div><div>      File "<stdin>", line 1, in <module></div><div>    TypeError: can't set attributes of built-in/extension type 'xml.etree.ElementTree.Element'</div>
<div><br></div><div>---</div><div><br></div><div>Q.  Is there way to maintain the same docstring without </div><div>    resorting to copying and pasting it in two places?</div><div><br></div><div>I tried to find an example in the source which addressed this, but</div>
<div>found that the docstrings in similar cases to be largely duplicated. </div><div>For instance, _datetimemodule.c, decimal_.c and _json.c all seem to</div><div>exhibit this docstring copy and pastage.</div></div></div>
</div><div><br></div></div>