On Sun, Apr 26, 2020 at 1:54 PM Tom Forbes <[email protected]> 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) !?
_______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/LWXMVO722UW2RWICINYCG6PPRLFCV6CA/ Code of Conduct: http://python.org/psf/codeofconduct/
