diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-07-05 23:31:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-05 23:31:54 (GMT) |
commit | 7b615a1573b8a119e8ad27915912da745756a547 (patch) | |
tree | f854d9b388f6fd0dcd1aabbd6e08bf1ec38f2c9a /Lib/test | |
parent | bb17e6f5de2bca85746a06d504029f90e85e3892 (diff) | |
download | cpython-7b615a1573b8a119e8ad27915912da745756a547.zip cpython-7b615a1573b8a119e8ad27915912da745756a547.tar.gz cpython-7b615a1573b8a119e8ad27915912da745756a547.tar.bz2 |
[3.12] gh-106292: restore checking __dict__ in cached_property.__get__ (GH-106380) (#106469)
gh-106292: restore checking __dict__ in cached_property.__get__ (GH-106380)
* gh-106292: restore checking __dict__ in cached_property.__get__
(cherry picked from commit 838406b4fc044c0b2f397c23275c69f16a76205b)
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_functools.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index d668fa4..c4eca0f 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -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() |