euporie.core.config.DefaultNamespace
- class euporie.core.config.DefaultNamespace(default_factory: Callable[[str], Any] | None = None, mapping_or_iterable: Mapping | Iterable[tuple[str, Any]] | None = None, /, **kwargs: Any)
A namespace that creates default values for undefined attributes using a factory function.
This class extends SimpleNamespace to provide automatic creation of default values when accessing undefined attributes, similar to collections.defaultdict but for object attributes.
- _factory
A callable that generates default values for undefined attributes. If None, AttributeError will be raised for undefined attributes.
Examples
>>> # Create namespace with list factory >>> ns = DefaultNamespace(default_factory=list) >>> ns.numbers.append(1) # Creates new list automatically >>> ns.numbers [1]
>>> # Create with initial values >>> ns = DefaultNamespace(default_factory=int, x=1, y=2) >>> ns.x 1 >>> ns.z # Creates new int (0) automatically 0