Visitar URL original
gh-98963: Restore the ability to have a dict-less property. by gpshead · Pull Request #105262 · python/cpython · GitHub
Skip to content
Merged
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
Next Next commit
Reword comments and NEWS.
  • Loading branch information
gpshead committed Jun 4, 2023
commit 996e70b78d9d1aac14faa0672ed94a673d53ba85
18 changes: 7 additions & 11 deletions Lib/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,16 @@ class PropertySubclassTests(unittest.TestCase):

def test_slots_docstring_copy_exception(self):
# A special case error that we preserve despite the GH-98963 behavior
# that would otherwise silence this error and not set a docstr.
# This came from https://github.com/python/cpython/commit/b18500d39d791c879e9904ebac293402b4a7cd34
# that would otherwise silently ignore this error.
# This came from commit b18500d39d791c879e9904ebac293402b4a7cd34
# as part of https://bugs.python.org/issue5890 which allowed docs to
# be set using property subclasses in the first place.
try:
# be set via property subclasses in the first place.
with self.assertRaises(AttributeError):
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")

def test_property_with_slots_no_docstring(self):
# https://github.com/python/cpython/issues/98963#issuecomment-1574413319
Expand All @@ -273,7 +269,7 @@ class slotted_prop(property):
def undocumented_getter():
return 4

p = slotted_prop(undocumented_getter) # no AttributeError
p = slotted_prop(undocumented_getter) # New in 3.12: no AttributeError
self.assertIsNone(getattr(p, "__doc__", None))

@unittest.skipIf(sys.flags.optimize >= 2,
Expand Down Expand Up @@ -303,14 +299,14 @@ class slotted_prop(property):
__slots__ = ("foo", "__doc__")

p = slotted_prop(doc="what's up")
self.assertEqual("what's up", p.__doc__) # meep meep!
self.assertEqual("what's up", p.__doc__) # new in 3.12: This gets set.

def documented_getter():
"""what's up getter doc?"""
return 4

p = slotted_prop(documented_getter)
self.assertEqual("what's up getter doc?", p.__doc__) # meep meep!
self.assertEqual("what's up getter doc?", p.__doc__)

@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Restore the ability for a subclass of :class:`property` to define
``__slots__`` or otherwise be dict-less by ignoring any attempt to set a
docstring on such a class. This behavior had regressed in 3.12beta1.
Restore the ability for a subclass of :class:`property` to define ``__slots__``
or otherwise be dict-less by ignoring failures to set a docstring on such a
class. This behavior had regressed in 3.12beta1. An :exc:`AttributeError`
where there had not previously been one was disruptive to existing code.