Option MergeΒΆ

This provides the MergedOptions class, which allows you to treat multiple python dictionaries as one.

Usage is either from the classmethod shortcut:

options = MergedOptions.using(options1, options2)

Or with the update method:

options = MergedOptions()

This object will otherwise behave like a dictionary. Note that When options are added, copies are made.

When you delete a key, it removes it from the first dictionary it can find. This means a key can change value when deleted rather than disappearing altogether


options1 = {'a':{'b':1, 'c':3}, 'b':5}
options2 = {'a':{'b':4, 'c':9}, 'd':7}
options = MergedOptions.using(options1, options2)

# options['a'] == MergedOptions(prefix='a', <same_options>, <same_overrides>)
# options['a']['b'] == 4
# options['a']['c'] == 9
# options['d'] == 7

del options['a']['c']
# options['a']['c'] == 3