Created
June 29, 2024 06:34
-
-
Save KaoruNishikawa/db18401693a5deb7418091bfc4685ce3 to your computer and use it in GitHub Desktop.
Count parentheses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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