Sometimes you want to prevent a config node from being changed accidentally.
Structured Configs can enable it by passing frozen=True in the dataclass definition. Using Structured Configs, you can annotate a dataclass as frozen. This is recursive and applies to all child nodes.
This will prevent modifications via code, command line overrides and config composition.
baud_rate: int = 19200
data_bits: int = 8
stop_bits: int = 1
cs = ConfigStore.instance()
def my_app(cfg: SerialPort) -> None:
if __name__ == "__main__":
$ python frozen.py data_bits=10
Error merging override data_bits=10
Cannot change read-only config container
NOTE: A crafty user can find many ways around this. This is just making it harder to change things accidentally.