Reusing a cached_property on different classes under the same name is OK.
(self)
| 3726 | ) |
| 3727 | |
| 3728 | def test_reuse_same_name(self): |
| 3729 | """Reusing a cached_property on different classes under the same name is OK.""" |
| 3730 | counter = 0 |
| 3731 | |
| 3732 | @py_functools.cached_property |
| 3733 | def _cp(_self): |
| 3734 | nonlocal counter |
| 3735 | counter += 1 |
| 3736 | return counter |
| 3737 | |
| 3738 | class A: |
| 3739 | cp = _cp |
| 3740 | |
| 3741 | class B: |
| 3742 | cp = _cp |
| 3743 | |
| 3744 | a = A() |
| 3745 | b = B() |
| 3746 | |
| 3747 | self.assertEqual(a.cp, 1) |
| 3748 | self.assertEqual(b.cp, 2) |
| 3749 | self.assertEqual(a.cp, 1) |
| 3750 | |
| 3751 | def test_set_name_not_called(self): |
| 3752 | cp = py_functools.cached_property(lambda s: None) |
nothing calls this directly
no test coverage detected