-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Description
Currently, inspect
and pydoc
use similar, but slightly different complex code to retrieve a doc string for object (class, function, method, etc). This is a consequence of two issues: bpo-15582 (#59787) and bpo-40257 (#84438).
In #59787, inheriting docstrings from parent class was added. It usually works fine for overridden methods, but for classes it is often wrong. If the parent class docstring says that it is an abstract class, a base class or a generic implementation class, showing this for a subclass is wrong. It is worse than not showing a docstring at all (like it was before #59787). So #84438 reverted this particular change. It fixed also other issue -- pydoc
now shows a docstring not only for classes and function, but for arbitrary objects if they have docstring. This allows to show docstring for typing.Any
and other pseudo-types. But there were complains against these changes, so they were reverted for inspect.getdoc()
. But taht behavior is wrong for pydoc
, so a modified version of inspect.getdoc()
was copied in pydoc
.
The problem is that that code is pretty complex. And any time we change it (for example #131116), we need to change in two places. It is easy to forgot to synchronize the code or introduce a bug. Also, the third-party code that use getdoc()
may need the behavior of the pydoc
version, which is not public.
The implementation should be shared. We may add options to control the behavior, and the default behavior may change in future. If there is a way to get the old behavior, there would be less complains.