[Python-Dev] pydoc for named tuples is missing methods

Benjamin Peterson benjamin at python.org
Mon Mar 14 03:53:47 CET 2011


2011/3/13 Tim Lesher <tlesher at gmail.com>:
> [I mentioned this to Raymond Hettinger after his PyCon talk, and I
> promised a bug and hopefully a patch. I don't see an obvious solution,
> though, so I'll ask here first.]
>
> Because named tuple prefixes a single underscore to its added method
> names (_asdict, _replace, and _make), those methods' docstrings are
> omitted from pydoc:
>
>>>> Point=collections.namedtuple('Point', 'x y')
>>>> help(Point)
> Help on class Point in module __main__:
> [output omitted; it excludes _asdict, _replace, and _make]
>
> pydoc's rules for name inclusion are in pydoc.visiblename():
>
> * If the name is in the hidden list, omit it
> * If the name looks like a __special_method__, include it
> * If the there is an "all" specified, then include it if it appears in all
> * Otherwise, include it if it doesn't begin with an underscore
>
> There doesn't seem to be an obvious way to get around these rules for
> named tuples... am I overlooking something?

No, probably we should add some sort of __yes_i_am_public__ override
attribute that pydoc looks for. It's such a pity that those methods
have to have underscores...



-- 
Regards,
Benjamin


More information about the Python-Dev mailing list