Visitar URL original
gh-98963: Add a note to the error for property subclasses without __doc__ by encukou · Pull Request #99058 · python/cpython · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move the note check to an existing test
  • Loading branch information
encukou committed Nov 3, 2022
commit 66428bc68973e2edee5358170d707a57ae1330df
11 changes: 0 additions & 11 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2359,17 +2359,6 @@ def test_testcapi_no_segfault(self):
class X(object):
p = property(_testcapi.test_with_docstring)

def test_subclass_with_nonwritable_doc(self):
# gh-98963: subclasses must have writable __doc__. A note is added to
# the exception in this surprising edge case.
class BadProperty(property):
__doc__ = property(lambda: None)
with self.assertRaises(AttributeError) as cm:
p = BadProperty(lambda: 123)
notes = cm.exception.__notes__
wanted = "subclasses of 'property' need to provide a writable __doc__"
self.assertTrue(any(note.startswith(wanted) for note in notes), notes)

def test_properties_plus(self):
class C(object):
foo = property(doc="hello")
Expand Down
12 changes: 7 additions & 5 deletions Lib/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,18 @@ class PropertySubSlots(property):
class PropertySubclassTests(unittest.TestCase):

def test_slots_docstring_copy_exception(self):
try:
with self.assertRaises(AttributeError) as cm:
class Foo(object):
@PropertySubSlots
def spam(self):
"""Trying to copy this docstring will raise an exception"""
return 1
except AttributeError:
pass
else:
raise Exception("AttributeError not raised")
# gh-98963: A note is added to the exception when we don't have
# a writable __doc__.
notes = cm.exception.__notes__
wanted = "subclasses of 'property' need to provide a writable __doc__"
self.assertTrue(any(note.startswith(wanted) for note in notes), notes)


@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
Expand Down