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)

clear()

Remove all options from this section across all layers.

Return type:

None

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, **kwargs)

Evaluate an option as a Python expression safely.

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

  • 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.

  • **kwargs (Any) – Additional keyword arguments forwarded to tranche.Tranche.getexpression().

  • dtype (type | None)

Returns:

Result of the evaluated expression, optionally cast.

Return type:

Any

getlist(option, dtype=<class 'str'>, **kwargs)

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.

  • **kwargs (Any) – Additional keyword arguments forwarded to tranche.Tranche.getlist().

Returns:

Parsed list with elements converted by dtype.

Return type:

list of T

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

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".

  • **kwargs (Any) – Additional keyword arguments forwarded to tranche.Tranche.getnumpy().

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

items()

The (option, value) pairs in this section.

Return type:

ItemsView[str, str]

keys()

The option names in this section.

Return type:

KeysView[str]

property name: str

The name of this section.

pop(option, default=<object object>)

Remove option and return its value across all layers.

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

  • default (Any, optional) – Value to return if the option is absent. If omitted, a KeyError is raised for a missing option.

Returns:

The removed value, or default if the option was absent.

Return type:

Any

popitem()

Remove and return an arbitrary (option, value) pair.

Raises:

KeyError – If the section has no options.

Return type:

tuple[str, str]

setdefault(option, value='')

Return option’s value, setting it to value first if absent.

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

  • value (Any, optional) – Value to set (and return) if the option does not yet exist.

Returns:

The existing or newly set value.

Return type:

str

update(other=(), /, **kwargs)

Update options from a mapping or iterable of pairs and/or keywords.

Mirrors dict.update; each value is stored in tranche’s runtime layer.

Parameters:
Return type:

None

values()

The option values in this section.

Return type:

ValuesView[str]