tranche.section

class tranche.section.Section(tranche, proxy, name)

Bases: object

Wrapper around configparser.SectionProxy exposing tranche helpers.

Provides section-scoped convenience methods while delegating all other behavior to the underlying SectionProxy.

Parameters:
  • tranche (Tranche)

  • proxy (SectionProxy)

  • name (str)

explain(option)

Explain provenance for an option in this section.

Returns a dictionary with the effective value, the source file path, and which layer provided it (“user” or “base”).

Parameters:

option (str) – Option name within this section.

Returns:

Dictionary with keys {"value", "source", "layer"}.

Return type:

dict

getexpression(option, dtype=None, backend=None, allow_numpy=False)

Evaluate an option as a Python expression safely.

Parameters:
  • option (str) – Option name within this section.

  • dtype (type, optional) – If provided, cast list/tuple elements or dict values.

  • backend ({"literal", "safe"} or None, optional) – Evaluation backend. None chooses "safe" when allow_numpy is True, otherwise "literal".

  • allow_numpy (bool, optional) – If True and using the “safe” backend, expose limited numpy functions under np/numpy.

Returns:

Result of the evaluated expression, optionally cast.

Return type:

Any

getlist(option, dtype=None)

Get an option value parsed as a list.

Parameters:
  • option (str) – Option name within this section.

  • dtype (Callable[[str], T], optional) – Converter applied to each item. Defaults to str.

Returns:

Parsed list with elements converted by dtype.

Return type:

list of T

getnumpy(option, dtype=None, backend=None)

Evaluate an expression with NumPy enabled.

Shortcut equivalent to getexpression(..., allow_numpy=True).

Parameters:
  • option (str) – Option name within this section.

  • dtype (type, optional) – If provided, cast list/tuple elements or dict values.

  • backend ({"literal", "safe"} or None, optional) – Backend override. None chooses "safe".

Returns:

Result of the evaluated expression, optionally cast.

Return type:

Any

has_option(option)

Check whether this section contains an option.

Parameters:

option (str) – Option name to check.

Returns:

True if the option exists, else False.

Return type:

bool