MCPcopy Create free account
hub / github.com/cdgriffith/Box / IndexOnce

Class IndexOnce

test/test_imul_index_comments.py:10–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class IndexOnce:
11 def __init__(self, value):
12 self.value = value
13 self.calls = 0
14
15 def __index__(self):
16 self.calls += 1
17 if self.calls > 1:
18 raise AssertionError("count evaluated twice")
19 return self.value
20
21
22@pytest.mark.parametrize("count", [2, 1, 0, -2])

Calls

no outgoing calls