Contributing#

Development Setup#

Clone and install in editable mode:

git clone https://github.com/jeankossaifi/zencfg
cd zencfg
pip install -e .

Run tests:

python -m pytest src/zencfg/tests/

Build documentation:

cd docs
sphinx-build -b html . _build/html

Internal Implementation#

These functions are used internally by ZenCFG. They’re documented here for contributors and advanced users who want to understand how the library works.

parse_value_to_type#

Converts values to their expected types using Pydantic validation.

zencfg.config.parse_value_to_type(value: Any, field_type: Type, strict: bool = True, path: str = '') Any[source]#

Parse a value to match its expected type.

Parameters:
  • value (Any) – The value to parse

  • field_type (Type) – The expected type

  • strict (bool) – If True, raises on type conversion errors. If False, falls back to original value if conversion fails.

  • path (str) – Path in the config hierarchy, used for error messages

Returns:

The parsed value

Return type:

Any

Raises:

TypeError – If value cannot be converted to the expected type and strict=True

is_configbase_type#

Checks if a type is a ConfigBase subclass or Union containing ConfigBase.

zencfg.config.is_configbase_type(tp: Any) bool[source]#

Returns True if type ‘tp’ is a subclass of ConfigBase OR a Union that includes a ConfigBase subclass.

gather_defaults#

Collects default values from a class and its inheritance hierarchy.

zencfg.config.gather_defaults(cls) dict[source]#

Gather all default (class-level) fields from the entire MRO, ensuring that child classes override parent defaults if present. Returns a dictionary of {field_name: default_value}.

Contributing Guidelines#

  • Follow existing code style

  • Add tests for new features

  • Update documentation as needed

  • Open an issue before major changes