cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Augment functools.cached_property tests for set/delete

Open gsakkis opened this issue 1 month ago • 2 comments

cached_property supports set and delete but this is not currently tested.

Minimal test extending TestCachedProperty.test_cached:

class TestCachedProperty(unittest.TestCase):
    def test_cached(self):
        item = CachedCostItem()
        self.assertEqual(item.cost, 2)
        self.assertEqual(item.cost, 2) # not 3

        item.cost = 42
        self.assertEqual(item.cost, 42)

        del item.cost
        self.assertEqual(item.cost, 3)
        self.assertEqual(item.cost, 3) # not 4

Linked PRs

  • gh-142645
  • gh-143393

gsakkis avatar Dec 04 '25 08:12 gsakkis

Do you want to create a PR? You are welcome.

serhiy-storchaka avatar Dec 04 '25 15:12 serhiy-storchaka

CC @ZeroIntensity (mentorship): tests

johnslavik avatar Dec 04 '25 18:12 johnslavik