GitHub

API reference for console.

Console output as effects, through a swappable Console service.

Each effect calls one method of the console in CurrentConsole: a shared LiveConsole (Node's console on stdout / stderr) unless one is provided. The console loggers write through it too, so a test can capture every line with a testing.TestConsole::

yield from console.log("hello", 42)
yield from console.with_group(work, label="setup")
yield from console.time("load")        # needs a Scope; logs on close

group and time hold their group or timer open until the scope closes; with_group and with_time around one effect.

Classes

Functions

assert_

assert_(condition, *args) -> Effect[None]

Write args as an assertion failure unless condition.

ParameterTypeDescription
conditionbool
argsobject = ()

Returns Effect[None]

def assert_(condition: bool, *args: object) -> Effect[None]:
    """Write ``args`` as an assertion failure unless ``condition``."""
    return _call(lambda c: c.assert_(condition, *args))

console_with

console_with(f) -> Effect[A, E, R]

Run f with the current console.

ParameterTypeDescription
fCallable[[Console], Effect[A, E, R]]

Returns Effect[A, E, R]

def console_with[A, E, R](f: Callable[[Console], Effect[A, E, R]]) -> Effect[A, E, R]:
    """Run ``f`` with the current console."""
    return _WithFiber(lambda fiber: f(fiber.get_ref(CurrentConsole)))

count

count(label='default') -> Effect[None]

Write how many times count was called with label.

ParameterTypeDescription
labelstr = 'default'

Returns Effect[None]

def count(label: str = "default") -> Effect[None]:
    """Write how many times ``count`` was called with ``label``."""
    return _call(lambda c: c.count(label))

count_reset

count_reset(label='default') -> Effect[None]
ParameterTypeDescription
labelstr = 'default'

Returns Effect[None]

def count_reset(label: str = "default") -> Effect[None]:
    return _call(lambda c: c.count_reset(label))

debug

debug(*args) -> Effect[None]
ParameterTypeDescription
argsobject = ()

Returns Effect[None]

def debug(*args: object) -> Effect[None]:
    return _call(lambda c: c.debug(*args))

dir

dir(item) -> Effect[None]

Write item pretty-printed.

ParameterTypeDescription
itemobject

Returns Effect[None]

def dir(item: object) -> Effect[None]:
    """Write ``item`` pretty-printed."""
    return _call(lambda c: c.dir(item))

error

error(*args) -> Effect[None]
ParameterTypeDescription
argsobject = ()

Returns Effect[None]

def error(*args: object) -> Effect[None]:
    return _call(lambda c: c.error(*args))

group

group(label=None, *, collapsed=False) -> Effect[None, Never, Scope]

Open a console group, closed when the scope closes.

ParameterTypeDescription
labelstr | None = None
collapsedbool = False

Returns Effect[None, Never, Scope]

def group(label: str | None = None, *, collapsed: bool = False) -> Effect[None, Never, Scope]:
    """Open a console group, closed when the scope closes."""
    return acquire_release(
        _call(_open_group(label, collapsed)), lambda _, _ex: _call(lambda c: c.group_end())
    )

info

info(*args) -> Effect[None]
ParameterTypeDescription
argsobject = ()

Returns Effect[None]

def info(*args: object) -> Effect[None]:
    return _call(lambda c: c.info(*args))

log

log(*args) -> Effect[None]
ParameterTypeDescription
argsobject = ()

Returns Effect[None]

def log(*args: object) -> Effect[None]:
    return _call(lambda c: c.log(*args))

table

table(data, properties=None) -> Effect[None]

Write data as a table (see LiveConsole.table).

ParameterTypeDescription
dataobject
propertiesSequence[str] | None = None

Returns Effect[None]

def table(data: object, properties: Sequence[str] | None = None) -> Effect[None]:
    """Write ``data`` as a table (see ``LiveConsole.table``)."""
    return _call(lambda c: c.table(data, properties))

time

time(label='default') -> Effect[None, Never, Scope]

Start a console timer; the scope's closing writes its time.

ParameterTypeDescription
labelstr = 'default'

Returns Effect[None, Never, Scope]

def time(label: str = "default") -> Effect[None, Never, Scope]:
    """Start a console timer; the scope's closing writes its time."""
    return acquire_release(
        _call(lambda c: c.time(label)), lambda _, _ex: _call(lambda c: c.time_end(label))
    )

time_log

time_log(label='default', *args) -> Effect[None]

Write the time since time(label) started, then args.

ParameterTypeDescription
labelstr = 'default'
argsobject = ()

Returns Effect[None]

def time_log(label: str = "default", *args: object) -> Effect[None]:
    """Write the time since ``time(label)`` started, then ``args``."""
    return _call(lambda c: c.time_log(label, *args))

trace

trace(*args) -> Effect[None]
ParameterTypeDescription
argsobject = ()

Returns Effect[None]

def trace(*args: object) -> Effect[None]:
    return _call(lambda c: c.trace(*args))

warn

warn(*args) -> Effect[None]
ParameterTypeDescription
argsobject = ()

Returns Effect[None]

def warn(*args: object) -> Effect[None]:
    return _call(lambda c: c.warn(*args))

with_group

with_group(eff, *, label=None, collapsed=False) -> Effect[A, E, R]

Run eff inside a console group.

ParameterTypeDescription
effEffect[A, E, R]
labelstr | None = None
collapsedbool = False

Returns Effect[A, E, R]

def with_group[A, E, R](
    eff: Effect[A, E, R], *, label: str | None = None, collapsed: bool = False
) -> Effect[A, E, R]:
    """Run ``eff`` inside a console group."""
    require_effect(eff, "eff")
    return acquire_use_release(
        _call(_open_group(label, collapsed)),
        lambda _: eff,
        lambda _, _ex: _call(lambda c: c.group_end()),
    )

with_time

with_time(eff, label='default') -> Effect[A, E, R]

Run eff and write how long it took.

ParameterTypeDescription
effEffect[A, E, R]
labelstr = 'default'

Returns Effect[A, E, R]

def with_time[A, E, R](eff: Effect[A, E, R], label: str = "default") -> Effect[A, E, R]:
    """Run ``eff`` and write how long it took."""
    require_effect(eff, "eff")
    return acquire_use_release(
        _call(lambda c: c.time(label)),
        lambda _: eff,
        lambda _, _ex: _call(lambda c: c.time_end(label)),
    )