MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / Counter

Class Counter

example_code/item_124_example_06.py:22–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20# Check types in this file with: python3 -m mypy <path>
21
22class Counter:
23 def __init__(self) -> None:
24 self.value: int = 0 # Field / variable annotation
25
26 def add(self, offset: int) -> None:
27 value += offset # Oops: forgot "self."
28
29 def get(self) -> int:
30 self.value # Oops: forgot "return"
31
32counter = Counter()
33counter.add(5)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected