Namespace

class app.util.namespace.Namespace[source]

Bases: Generic

A flexible namespace object that can be accessed like a dictionary or using attributes.

This class provides a dynamic container for attributes, supporting both attribute and dict-style access. It supports freezing (to prevent further modification), recursive merging, and can be extended with mixins for logging, naming, and hierarchy. Used as a base for configuration and data structures throughout pygaindalf.

Inheritance diagram of Namespace

Inheritance Diagram for Namespace

Methods

__init__(*[, frozen_schema, frozen_namespace])

Initialize a Namespace instance.

asdict([recursive, private, protected, public])

Convert the namespace to a dictionary.

freeze_namespace([freeze, recursive, temporary])

Freeze the namespace.

freeze_schema([freeze, recursive, temporary])

Freeze the schema of the namespace.

merge(d)

Merge a dictionary into the namespace.

unfreeze_namespace([recursive, temporary])

Unfreeze the namespace.

unfreeze_schema([recursive, temporary])

Unfreeze the schema of the namespace.

Attributes

Attribute

Default

DictView

NAMESPACE__DEFAULT

NAMESPACE__FROZEN_NAMESPACE__ALLOW_PRIVATE

NAMESPACE__FROZEN_SCHEMA__ALLOW_PRIVATE

NAMESPACE__STICKY

NAMESPACE__STICKY__DELIMITER

NO_DEFAULT

frozen_namespace

Get the frozen state of the namespace.

frozen_schema

Get the frozen state of the schema.

Attribute = Attribute
Default = Default
DictView = DictView
class FreezableNamespaceProtocol[source]

Bases: Protocol

__init__(*args, **kwargs)
freeze_namespace(freeze=True, *, recursive=False, temporary=False)[source]
Return type:

EnterExitCall | None

Parameters:
property frozen_namespace: bool
unfreeze_namespace(recursive=False, temporary=False)[source]
Return type:

EnterExitCall | None

Parameters:
class FreezableSchemaProtocol[source]

Bases: Protocol

__init__(*args, **kwargs)
freeze_schema(freeze=True, *, recursive=False, temporary=False)[source]
Return type:

EnterExitCall | None

Parameters:
property frozen_schema: bool
unfreeze_schema(recursive=False, temporary=False)[source]
Return type:

EnterExitCall | None

Parameters:
NAMESPACE__DEFAULT: TypeAliasType = <app.util.namespace.namespace.Namespace.NoDefault object>
NAMESPACE__FROZEN_NAMESPACE__ALLOW_PRIVATE: bool = False
NAMESPACE__FROZEN_SCHEMA__ALLOW_PRIVATE: bool = False
NAMESPACE__STICKY: bool = False
NAMESPACE__STICKY__DELIMITER: str | None = None
NO_DEFAULT = <app.util.namespace.namespace.Namespace.NoDefault object>
class NoDefault[source]

Bases: object

__init__(*, frozen_schema=False, frozen_namespace=False, **kwargs)[source]

Initialize a Namespace instance.

Parameters:
  • frozen_schema (bool) – If True, freeze the schema (no new keys allowed).

  • frozen_namespace (bool) – If True, freeze the namespace (no changes allowed).

  • **kwargs (TypeAliasType) – Initial key-value pairs to populate the namespace.

Raises:

TypeError – If mixin order is incorrect in the MRO.

asdict(recursive=True, private=False, protected=True, public=True)[source]

Convert the namespace to a dictionary.

Parameters:
  • recursive (bool) – If True, convert nested namespaces recursively.

  • private (bool) – If True, include private attributes.

  • protected (bool) – If True, include protected attributes.

  • public (bool) – If True, include public attributes.

Returns:

The namespace as a dictionary.

Return type:

dict

freeze_namespace(freeze=True, *, recursive=False, temporary=False)[source]

Freeze the namespace.

Parameters:
  • freeze (bool) – If True, freeze the namespace.

  • recursive (bool) – If True, apply freezing recursively to nested namespaces.

  • temporary (bool) – If True, apply freezing temporarily.

Returns:

A context manager for temporary freezing.

Return type:

EnterExitCall

freeze_schema(freeze=True, *, recursive=False, temporary=False)[source]

Freeze the schema of the namespace.

Parameters:
  • freeze (bool) – If True, freeze the schema.

  • recursive (bool) – If True, apply freezing recursively to nested namespaces.

  • temporary (bool) – If True, apply freezing temporarily.

Returns:

A context manager for temporary freezing.

Return type:

EnterExitCall

property frozen_namespace: bool

Get the frozen state of the namespace.

Returns:

True if the namespace is frozen, False otherwise.

Return type:

bool

property frozen_schema: bool

Get the frozen state of the schema.

Returns:

True if the schema is frozen, False otherwise.

Return type:

bool

merge(d)[source]

Merge a dictionary into the namespace.

Parameters:

d (dict) – The dictionary to merge.

Return type:

None

unfreeze_namespace(recursive=False, temporary=False)[source]

Unfreeze the namespace.

Parameters:
  • recursive (bool) – If True, apply unfreezing recursively to nested namespaces.

  • temporary (bool) – If True, apply unfreezing temporarily.

Returns:

A context manager for temporary unfreezing.

Return type:

EnterExitCall

unfreeze_schema(recursive=False, temporary=False)[source]

Unfreeze the schema of the namespace.

Parameters:
  • recursive (bool) – If True, apply unfreezing recursively to nested namespaces.

  • temporary (bool) – If True, apply unfreezing temporarily.

Returns:

A context manager for temporary unfreezing.

Return type:

EnterExitCall