While the implementation is great, including locking to ensure the underlying function is called only once, this only works for properties rather than methods defined in modules (and more generally, any method).

On 26 Apr 2020, at 20:27, Matthew Einhorn <moiein2000@gmail.com> wrote:

On Sun, Apr 26, 2020 at 1:54 PM Tom Forbes <tom@tomforb.es> wrote:
This is a good idea but some cases need to be lazily evaluated. Without that property `once()` loses a lot of utility. In the case of Django some of the decorated functions create objects that cannot be instantiated until the Django settings have been loaded, which rules out calling them from the module scope.

I believe this use case of lazily initialising objects that cannot be created in the module scope is encountered by other projects. One example off the top of my head might be a database connection, or some other stateful client, that you want a single instance of but want to actually create at some point in the future.

I'm surprised no one mentioned  cached_property (https://docs.python.org/dev/library/functools.html#functools.cached_property)!?