Python 3.10 is now available in preview.


A base class for a configuration object.

Inherits From: expected_type

Subclasses should provide validation functions for every configuration option they accept. Any public function decorated with ConfigOption is assumed to be a validation function for an option of the same name. All validation functions take a single non-None value to validate and must throw an exception or return the value to store.

This class forces subclasses to be immutable and exposes a read-only property for every accepted configuration option. Configuration options set by passing keyword arguments to the constructor. The constructor and merge function are designed to avoid creating redundant copies and may return the configuration objects passed to them if appropriate.

Setting an option to None is the same as not specifying the option except in the case where the 'config' argument is given. In this case the value on 'config' of the same name is ignored. Options that are not specified will return 'None' when accessed.

config Optional base configuration providing default values for parameters not specified in the keyword arguments.
**kwargs Configuration options to store on this object.



View source

True if configuration obj handles all options of this class.

Use this method rather than isinstance(obj, cls) to test if a configuration object handles the options of cls (is_configuration is handled specially for results of merge which may handle the options of unrelated configuration classes).

obj the object to test.


View source

Merge two configurations.

The configuration given as an argument (if any) takes priority; defaults are filled in from the current configuration.

config Configuration providing overrides, or None (but cannot be omitted).

Either a new configuration object or (if it would be equivalent) self or the config argument unchanged, but never None.

BadArgumentError if self or config are of configurations classes with conflicting options (i.e. the same option name defined in two different configuration classes).


View source

Return self==value.


View source

Return self!=value.