Created
January 14, 2026 11:58
-
-
Save barseghyanartur/be9a4404bbf3dc5a9edcd1c1cf22d048 to your computer and use it in GitHub Desktop.
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
| import functools | |
| import typing | |
| # Use a conditional expression directly. | |
| # This evaluates to the function 'cache' itself, which the @ operator then calls. | |
| @ (functools.cache if not typing.TYPE_CHECKING else lambda f: f) | |
| def a(): | |
| print("Aaaa") | |
| a() # Prints "Aaaa" | |
| a() # Returns cached value, prints nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment