diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-10-29 08:15:50 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-10-29 08:15:50 +0200 |
commit | ac4bdcc80e986bdd5b9d10ab0bce35aabb790a3e (patch) | |
tree | ab7584880b723f516f0ac580241396e850128a63 | |
parent | f8152c67f52874cd4aa63f1cb3e1216382f98057 (diff) | |
download | cpython-git-ac4bdcc80e986bdd5b9d10ab0bce35aabb790a3e.tar.gz |
Issue #25503: Fixed inspect.getdoc() for inherited docstrings of properties.
Original patch by John Mark Vandenberg.
-rw-r--r-- | Lib/inspect.py | 13 | ||||
-rw-r--r-- | Lib/test/inspect_fodder.py | 7 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 4 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
5 files changed, 19 insertions, 9 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index bf4f87d5cf..b65bec7adf 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -527,17 +527,18 @@ def _finddoc(obj): cls = self else: cls = self.__class__ - elif ismethoddescriptor(obj) or isdatadescriptor(obj): - name = obj.__name__ - cls = obj.__objclass__ - if getattr(cls, name) is not obj: - return None + # Should be tested before isdatadescriptor(). elif isinstance(obj, property): - func = f.fget + func = obj.fget name = func.__name__ cls = _findclass(func) if cls is None or getattr(cls, name) is not obj: return None + elif ismethoddescriptor(obj) or isdatadescriptor(obj): + name = obj.__name__ + cls = obj.__objclass__ + if getattr(cls, name) is not obj: + return None else: return None diff --git a/Lib/test/inspect_fodder.py b/Lib/test/inspect_fodder.py index 068d8258b9..711badad84 100644 --- a/Lib/test/inspect_fodder.py +++ b/Lib/test/inspect_fodder.py @@ -45,14 +45,17 @@ class StupidGit: self.ex = sys.exc_info() self.tr = inspect.trace() + @property def contradiction(self): 'The automatic gainsaying.' pass -# line 48 +# line 53 class MalodorousPervert(StupidGit): def abuse(self, a, b, c): pass + + @property def contradiction(self): pass @@ -64,6 +67,8 @@ class ParrotDroppings: class FesteringGob(MalodorousPervert, ParrotDroppings): def abuse(self, a, b, c): pass + + @property def contradiction(self): pass diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 955b2adcb2..69ddb514d6 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -393,8 +393,8 @@ class TestRetrievingSourceCode(GetSourceBase): def test_getsource(self): self.assertSourceEqual(git.abuse, 29, 39) - self.assertSourceEqual(mod.StupidGit, 21, 50) - self.assertSourceEqual(mod.lobbest, 70, 71) + self.assertSourceEqual(mod.StupidGit, 21, 51) + self.assertSourceEqual(mod.lobbest, 75, 76) def test_getsourcefile(self): self.assertEqual(normcase(inspect.getsourcefile(mod.spam)), modfile) @@ -1480,6 +1480,7 @@ Lukas Vacek Ville Vainio Andi Vajda Case Van Horsen +John Mark Vandenberg Kyle VanderBeek Andrew Vant Atul Varma @@ -45,6 +45,9 @@ Core and Builtins Library ------- +- Issue #25503: Fixed inspect.getdoc() for inherited docstrings of properties. + Original patch by John Mark Vandenberg. + - Issue #21827: Fixed textwrap.dedent() for the case when largest common whitespace is a substring of smallest leading whitespace. Based on patch by Robert Li. |