License

This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2, as
published by Sam Hocevar. See the COPYING file for more details.

This program is free software. It comes without any warranty, to the
extent permitted by applicable law.

Overview

List of objects:

weak_and_lazy decorator class for weak and lazy reference
attributes

ref data class used to bind instance and loader params

Running this module from the command line will execute the doctests. To
enable verbose mode, run:

python weak_and_lazy.py -v

API

weak_and_lazy

Decorator class for weak and lazy references.

Description

Decorator class for a property that looks like a reference to outsiders
but is in fact a dynamic object-loader. After loading it stores a weak
reference to the object so it can be remembered until it gets destroyed.

This means that the referenced object

will be loaded only if and when it is needed

can be garbage collected when it is not in use anymore

Why use it?

You probably do not need it, if you are asking this.

Still, for what in the world might that be useful?

Suppose you program a video game with several levels. As the levels have
very intense memory requirements, you want to load only those into
memory which you actually need at the moment. If a level is not needed
anymore (every player left the level), the garbage collector should be
able to tear it into the abyss. And while fulfilling these requirements
the interface should still feel like you are using normal references.
That is for what you can use weak-and-lazy.