snakeoil.klass.properties module

JIT related function

snakeoil.klass.properties.jit_attr(func: ~typing.Callable[[~typing.Any], ~snakeoil.klass.properties.T], kls=<function _internal_jit_attr>, uncached_val: ~typing.Any = <class 'snakeoil.klass.properties._singleton_kls'>) T[source]

decorator to JIT generate, and cache the wrapped functions result in ‘_’ + func.__name__ on the instance.

Parameters:
  • func – function to wrap

  • kls – internal arg, overridden if you need a tweaked version of _internal_jit_attr

  • uncached_val – the value to treat as missing/force regeneration when accessing the instance. Note this normally defaults to a singleton that will not be in use anywhere else.

Returns:

functor implementing the described behaviour

snakeoil.klass.properties.jit_attr_ext_method(func_name: str, stored_attr_name: str, use_cls_setattr=False, kls=<function _internal_jit_attr>, uncached_val: ~typing.Any = <class 'snakeoil.klass.properties._singleton_kls'>, doc=None)[source]

Decorator handing maximal control of attribute JIT’ing to the invoker.

See internal_jit_attr for documentation of the misc params.

Generally speaking, you only need this when you are doing something rather special.

snakeoil.klass.properties.jit_attr_named(stored_attr_name: str, use_cls_setattr=False, kls=<function _internal_jit_attr>, uncached_val: ~typing.Any = <class 'snakeoil.klass.properties._singleton_kls'>, doc=None)[source]

Version of jit_attr() decorator that allows for explicit control over the attribute name used to store the cache value.

See _internal_jit_attr for documentation of the misc params.

snakeoil.klass.properties.jit_attr_none(func: ~typing.Callable[[~typing.Any], ~snakeoil.klass.properties.T], kls=<function _internal_jit_attr>) T[source]

Version of jit_attr() decorator that forces the uncached_val to None.

This is mainly useful so that if any out of band forced regeneration of the value, they know they just have to write None to the attribute to force regeneration.