diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-06-11 09:52:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-11 09:52:27 (GMT) |
commit | f386cc96201bc14ec619108d696951033c56d39a (patch) | |
tree | 56d5126016442d36615184d3e8be50d49d95fa48 /Lib/test/test_property.py | |
parent | 7993268beb9442c063d142860135bd5d84c2946e (diff) | |
download | cpython-f386cc96201bc14ec619108d696951033c56d39a.zip cpython-f386cc96201bc14ec619108d696951033c56d39a.tar.gz cpython-f386cc96201bc14ec619108d696951033c56d39a.tar.bz2 |
[3.13] bpo-24766: doc= argument to subclasses of property not handled correctly (GH-2487) (GH-120305)
(cherry picked from commit 4829522b8d3e1a28930f1cccfcc9635e035a0eb4)
Co-authored-by: E. M. Bray <erik.bray@lri.fr>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_property.py')
-rw-r--r-- | Lib/test/test_property.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_property.py b/Lib/test/test_property.py index 408e64f..b7a2219 100644 --- a/Lib/test/test_property.py +++ b/Lib/test/test_property.py @@ -465,6 +465,40 @@ class PropertySubclassTests(unittest.TestCase): @unittest.skipIf(sys.flags.optimize >= 2, "Docstrings are omitted with -O2 and above") + def test_prefer_explicit_doc(self): + # Issue 25757: subclasses of property lose docstring + self.assertEqual(property(doc="explicit doc").__doc__, "explicit doc") + self.assertEqual(PropertySub(doc="explicit doc").__doc__, "explicit doc") + + class Foo: + spam = PropertySub(doc="spam explicit doc") + + @spam.getter + def spam(self): + """ignored as doc already set""" + return 1 + + def _stuff_getter(self): + """ignored as doc set directly""" + stuff = PropertySub(doc="stuff doc argument", fget=_stuff_getter) + + #self.assertEqual(Foo.spam.__doc__, "spam explicit doc") + self.assertEqual(Foo.stuff.__doc__, "stuff doc argument") + + def test_property_no_doc_on_getter(self): + # If a property's getter has no __doc__ then the property's doc should + # be None; test that this is consistent with subclasses as well; see + # GH-2487 + class NoDoc: + @property + def __doc__(self): + raise AttributeError + + self.assertEqual(property(NoDoc()).__doc__, None) + self.assertEqual(PropertySub(NoDoc()).__doc__, None) + + @unittest.skipIf(sys.flags.optimize >= 2, + "Docstrings are omitted with -O2 and above") def test_property_setter_copies_getter_docstring(self): class Foo(object): def __init__(self): self._spam = 1 |