colour.utilities.LazyCanonicalMapping#

class colour.utilities.LazyCanonicalMapping(data: collections.abc.Generator | collections.abc.Mapping | None = None, **kwargs: Any)[source]#

Bases: colour.utilities.data_structures.CanonicalMapping

Implement a lazy delimiter and case-insensitive dict-like object inheriting from colour.utilities.CanonicalMapping class.

The lazy retrieval is performed as follows: If the value is a callable, then it is evaluated and its return value is stored in place of the current value.

Parameters
  • data (Generator | Mapping | None) – Data to store into the lazy delimiter and case-insensitive dict-like object at initialisation.

  • kwargs (Any) – Key / value pairs to store into the mapping at initialisation.

Return type

None

Methods

Examples

>>> def callable_a():
...     print(2)
...     return 2
...
>>> methods = LazyCanonicalMapping({"McCamy": 1, "Hernandez": callable_a})
>>> methods["mccamy"]
1
>>> methods["hernandez"]
2
2
__getitem__(item: str | Any) Any[source]#

Return the value of given item from the lazy delimiter and case-insensitive dict-like object.

Parameters

item (str | Any) – Item to retrieve the value of from the lazy delimiter and case-insensitive dict-like object.

Returns

Item value.

Return type

object