Skip to content

Warnings

wybthon._warnings

_warnings

Development-mode warnings and error reporting.

A process-wide DEV_MODE flag and helpers that surface clear, actionable messages during development while keeping production builds quiet. All output goes to sys.stderr.

Dev-mode diagnostics raised elsewhere in the framework:

  • Top-level reactive read: a signal, memo, or prop was called at the top level of a component body, where the read isn't tracked.
  • Write in tracking scope: a signal was written inside a memo, a single-function effect, or a reactive hole (WriteInScopeError).
  • Static list in For: For received a plain list instead of an accessor, so it will only render once.

Functions:

Name Description
set_dev_mode

Enable or disable development mode diagnostics globally.

is_dev_mode

Return whether development mode is currently active.

warn

Print a development-mode warning to stderr (no-op when dev mode is off).

warn_once

Print message at most once per (category, key) pair.

log_error

Log an error to stderr, with a traceback in dev mode.

component_name

Return a human-readable display name for a component or tag.

warn_each_plain_list

Warn that For received a static list.

Attributes:

Name Type Description
DEV_MODE bool

Process-wide flag toggling Wybthon's development diagnostics.

DEV_MODE module-attribute

DEV_MODE: bool = True

Process-wide flag toggling Wybthon's development diagnostics.

Defaults to True. Production builds should call set_dev_mode(False) at startup.

set_dev_mode

set_dev_mode(enabled: bool) -> None

Enable or disable development mode diagnostics globally.

Parameters:

Name Type Description Default
enabled bool

When False, warn and warn_once become no-ops, WriteInScopeError is not raised, and tracebacks are suppressed in log_error.

required

is_dev_mode

is_dev_mode() -> bool

Return whether development mode is currently active.

warn

warn(message: str) -> None

Print a development-mode warning to stderr (no-op when dev mode is off).

warn_once

warn_once(category: str, key: Any, message: str) -> None

Print message at most once per (category, key) pair.

log_error

log_error(message: str, error: BaseException | None = None) -> None

Log an error to stderr, with a traceback in dev mode.

Always logs regardless of DEV_MODE, since errors indicate real problems.

component_name

component_name(comp: Any) -> str

Return a human-readable display name for a component or tag.

warn_each_plain_list

warn_each_plain_list(component: Any) -> None

Warn that For received a static list.

What's in this module

_warnings is Wybthon's lightweight development-mode diagnostics layer. It gives the framework a single place to surface actionable warnings and error tracebacks while developing. Warning output and exception tracebacks can be disabled for production; error messages still go to stderr.

Three things live here:

  • Dev-mode toggling: DEV_MODE defaults to True. Call set_dev_mode(False) at startup to silence warnings and traceback printing for production builds. This also disables WriteInScopeError for signal and store writes inside tracking scopes. is_dev_mode() reports the current state. Both are re-exported from the top-level wybthon package.
  • Warnings: warn prints a message to stderr every time it's called (a no-op when dev mode is off), while warn_once deduplicates by a (category, key) pair so repeated calls with the same pair only log once per process. The reactive system uses this path for untracked reads of signals, memos, and props at the top level of a component body. warn_each_plain_list also uses it when For receives a static list or tuple.
  • Error logging: log_error always prints, regardless of DEV_MODE; in dev mode it also prints the full traceback of an attached exception.

component_name is a small formatting helper shared by the warning functions above to produce a readable name for a tag string, a function component, or a class instance in warning text.

Application code doesn't usually call into _warnings directly beyond set_dev_mode/is_dev_mode. The other helpers are used internally by the reactive system and flow-control primitives to flag common reactivity mistakes early.

See also

  • Reactivity: explains tracked reads and the WriteInScopeError diagnostic.
  • flow: calls warn_each_plain_list when For receives a static list or tuple instead of an accessor.