colour.utilities.LazyCaseInsensitiveMapping#

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

Bases: colour.utilities.data_structures.CaseInsensitiveMapping

Implement a lazy case-insensitive dict-like object inheriting from CaseInsensitiveMapping class.

Allows lay values retrieving from keys while ignoring the key case. The keys are expected to be str or str-like objects supporting the str.lower() method.

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 (Optional[Union[Generator, Mapping]]) – Data to store into the lazy 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 = LazyCaseInsensitiveMapping(
...     {'McCamy': 1, 'Hernandez': callable_a})
>>> methods['mccamy']
1
>>> methods['hernandez']
2
2
__getitem__(item: Union[str, Any]) Any[source]#

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

Parameters

item (Union[str, Any]) – Item to retrieve the value of from the case-insensitive dict-like object.

Returns

Item value.

Return type

object

Notes

  • The item value is retrieved by using its lower-case variant.