MCPcopy Index your code
hub / github.com/python/cpython / test_reuse_same_name

Method test_reuse_same_name

Lib/test/test_functools.py:3728–3749  ·  view source on GitHub ↗

Reusing a cached_property on different classes under the same name is OK.

(self)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 3

AClass · 0.70
BClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected