mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-106292: restore checking __dict__ in cached_property.__get__ (#106380)
* gh-106292: restore checking __dict__ in cached_property.__get__ Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
This commit is contained in:
parent
217f47d6e5
commit
838406b4fc
3 changed files with 36 additions and 10 deletions
|
@ -3037,6 +3037,25 @@ class TestCachedProperty(unittest.TestCase):
|
|||
def test_doc(self):
|
||||
self.assertEqual(CachedCostItem.cost.__doc__, "The cost of the item.")
|
||||
|
||||
def test_subclass_with___set__(self):
|
||||
"""Caching still works for a subclass defining __set__."""
|
||||
class readonly_cached_property(py_functools.cached_property):
|
||||
def __set__(self, obj, value):
|
||||
raise AttributeError("read only property")
|
||||
|
||||
class Test:
|
||||
def __init__(self, prop):
|
||||
self._prop = prop
|
||||
|
||||
@readonly_cached_property
|
||||
def prop(self):
|
||||
return self._prop
|
||||
|
||||
t = Test(1)
|
||||
self.assertEqual(t.prop, 1)
|
||||
t._prop = 999
|
||||
self.assertEqual(t.prop, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue