[issue15582] Enhance inspect.getdoc to follow inheritance chains
Claudiu Popa
report at bugs.python.org
Sat Jan 17 16:19:58 CET 2015
Claudiu Popa added the comment:
Yury, regarding your last message, is it actually possible to have a subclass which doesn't have a __doc__ attribute in its __dict__, except using slots? __doc__ seems to be set to None every time if it's not specified, so I don't know how could I detect the case where the client sets '__doc__ = None' himself.
The following example might be more explanatory:
>>> class A:
... __doc__ = "a"
...
>>> inspect.getdoc(A)
'a'
>>> inspect.getdoc(A())
'a'
>>> class B(A):
... __doc__ = None
...
>>> vars(B)
mappingproxy({'__doc__': None, '__module__': '__main__'})
>>> B.__dict__
mappingproxy({'__doc__': None, '__module__': '__main__'})
>>> class C(A): pass
...
>>> vars(C)
mappingproxy({'__doc__': None, '__module__': '__main__'})
>>>
Nevertheless, my patch ignores this case, since it operates only on methods. When trying to do inspect.getdoc(Child, parent=Parent), it will try to look for an attribute 'Child' in the mro of Parent and thus it will return None, since this doesn't exist (this can actually be a problem, if that attribute actually exist).
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15582>
_______________________________________
More information about the Python-bugs-list
mailing list