gwexpy.table.SegmentCell

class gwexpy.table.SegmentCell(value: Any | None = None, loader: Callable[[], Any] | None = None, cacheable: bool = True)[source]

Bases: object

A single lazy-loadable payload cell.

Parameters:
  • value (Any | None) – The concrete payload object. May be None when a loader is set.

  • loader (collections.abc.Callable[[], Any] | None) – A zero-argument callable that returns the payload. Ignored when value is already set.

  • cacheable (bool) – When True (default) the result of loader is stored in value after the first call, so subsequent calls return directly.

Examples

>>> cell = SegmentCell(loader=lambda: 42, cacheable=True)
>>> cell.get()
42
>>> cell.is_loaded()
True
__init__(value: Any | None = None, loader: Callable[[], Any] | None = None, cacheable: bool = True) None

Methods

__init__([value, loader, cacheable])

clear()

Discard the cached value so the next get() call re-invokes the loader.

get()

Return the payload, loading it if necessary.

is_loaded()

Return True if the value has been loaded (or was set directly).

Attributes

cacheable

loader

value

value: Any | None = None
loader: Callable[[], Any] | None = None
cacheable: bool = True
get() Any[source]

Return the payload, loading it if necessary.

Returns:

The resolved payload.

Return type:

object

Raises:

ValueError – If both value and loader are None.

is_loaded() bool[source]

Return True if the value has been loaded (or was set directly).

clear() None[source]

Discard the cached value so the next get() call re-invokes the loader.