classification
Title: Enhance inspect.getdoc to follow inheritance chains
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, eric.snow, ncoghlan
Priority: normal Keywords:

Created on 2012-08-08 02:52 by ncoghlan, last changed 2012-08-10 19:31 by eric.snow.

Messages (2)
msg167654 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-08-08 02:52
Currently, if you override a method from a base class, the docstring is not inherited, even if it remains accurate.

This issue proposes an enhancement to inspect.getdoc() that allows the docstring to be retrieved from the inheritance hierarchy in the case where it is not overridden in the subclass by providing an explicit docstring.

Specifically, in the case where obj.__doc__ is None, and either the first parameter is a bound method, or a class object is passed in as the second parameter, inspect.getdoc will search the MRO based on obj.__name__ until it finds an attribute with a non-None __doc__ value.

(In Python 2, this could have been automatic for both bound and unbound methods. Unfortunately, there are no unbound methods in Python 3, so the second parameter is needed to handle the unbound method case)
msg167909 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-08-10 19:31
I have just the thing for this, but haven't had a chance to put a patch together.  I might be able to get to it in the next week if Dave "bitey" Beazley isn't too much of a distraction.  :)
History
Date User Action Args
2012-08-10 19:31:17eric.snowsetmessages: + msg167909
2012-08-08 22:34:54eric.araujosetnosy: + eric.araujo
2012-08-08 02:52:13ncoghlancreate