diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-05-18 17:25:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-18 17:25:07 (GMT) |
commit | 08b47c367a08f571a986366aa33828d3951fa88d (patch) | |
tree | be06ca168536a48a19f2a093192ad7137ff8aa3c /Lib/inspect.py | |
parent | 98e42d1f882b9b59f587d538c562dbc7d11c64c3 (diff) | |
download | cpython-08b47c367a08f571a986366aa33828d3951fa88d.zip cpython-08b47c367a08f571a986366aa33828d3951fa88d.tar.gz cpython-08b47c367a08f571a986366aa33828d3951fa88d.tar.bz2 |
bpo-40257: Revert changes to inspect.getdoc() (GH-20073)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index ad7e8cb..887a342 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -543,6 +543,17 @@ def _findclass(func): return cls def _finddoc(obj): + if isclass(obj): + for base in obj.__mro__: + if base is not object: + try: + doc = base.__doc__ + except AttributeError: + continue + if doc is not None: + return doc + return None + if ismethod(obj): name = obj.__func__.__name__ self = obj.__self__ @@ -586,35 +597,23 @@ def _finddoc(obj): return None for base in cls.__mro__: try: - doc = _getowndoc(getattr(base, name)) + doc = getattr(base, name).__doc__ except AttributeError: continue if doc is not None: return doc return None -def _getowndoc(obj): - """Get the documentation string for an object if it is not - inherited from its class.""" - try: - doc = object.__getattribute__(obj, '__doc__') - if doc is None: - return None - if obj is not type: - typedoc = type(obj).__doc__ - if isinstance(typedoc, str) and typedoc == doc: - return None - return doc - except AttributeError: - return None - def getdoc(object): """Get the documentation string for an object. All tabs are expanded to spaces. To clean up docstrings that are indented to line up with blocks of code, any whitespace than can be uniformly removed from the second line onwards is removed.""" - doc = _getowndoc(object) + try: + doc = object.__doc__ + except AttributeError: + return None if doc is None: try: doc = _finddoc(object) |