Skip to content

Instantly share code, notes, and snippets.

@KaoruNishikawa
Created June 29, 2024 06:34
Show Gist options
  • Select an option

  • Save KaoruNishikawa/db18401693a5deb7418091bfc4685ce3 to your computer and use it in GitHub Desktop.

Select an option

Save KaoruNishikawa/db18401693a5deb7418091bfc4685ce3 to your computer and use it in GitHub Desktop.
Count parentheses
class CallCounter:
def __init__(self) -> None:
self._count = 1
@property
def count(self) -> int:
return self._count
def __call__(self) -> "CallCounter":
self._count += 1
return self
assert CallCounter()().count == 2
assert CallCounter()()()()()()()()()().count == 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment