lisa.utils.LazyMapping#

class lisa.utils.LazyMapping(*args, **kwargs)[source]#

Bases: Mapping

Lazy Mapping dict-like class for elements evaluated on the fly.

It takes the same set of arguments as a dict with keys as the mapping keys and values as closures that take a key and return the value. The class does no automatic memoization but memoization can easily be achieved using functools.lru_cache(), as shown in the example below.

Example:

LazyMapping({
    x: lru_cache()(lambda k: k + 42)
    for x in [1, 2, 3, 4]
})

Attributes

__reversed__ inherited

See collections.abc.Mapping.__reversed__

Methods

__getitem__()

__iter__()

__len__()

__class_getitem__() inherited

See collections.abc.Iterable.__class_getitem__()

__contains__() inherited

See collections.abc.Mapping.__contains__()

get() inherited

See collections.abc.Mapping.get()

items() inherited

See collections.abc.Mapping.items()

keys() inherited

See collections.abc.Mapping.keys()

values() inherited

See collections.abc.Mapping.values()

Attributes#

LazyMapping.__reversed__ = None#

Methods#

LazyMapping.__getitem__(key)[source]#
LazyMapping.__iter__()[source]#
LazyMapping.__len__()[source]#
classmethod LazyMapping.__class_getitem__()#

Inherited method, see collections.abc.Iterable.__class_getitem__()

LazyMapping.__contains__()#

Inherited method, see collections.abc.Mapping.__contains__()

LazyMapping.get()#

Inherited method, see collections.abc.Mapping.get()

LazyMapping.items()#

Inherited method, see collections.abc.Mapping.items()

LazyMapping.keys()#

Inherited method, see collections.abc.Mapping.keys()

LazyMapping.values()#

Inherited method, see collections.abc.Mapping.values()