colour.utilities.LazyCanonicalMapping#

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

Bases: CanonicalMapping

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

This class extends CanonicalMapping with lazy evaluation capabilities. When a value is a callable, it is automatically evaluated upon first access and its return value is cached, replacing the original callable for subsequent retrievals.

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.

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 the specified 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